Re: Passing PostgreSQL resource

From: Date: Wed, 12 Feb 2003 18:52:04 +0000
Subject: Re: Passing PostgreSQL resource
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-135347@lists.php.net to get a copy of this message
i will use it for the moment but i was thinking in a "light" solution ... i dont like the idea of creating a temp table for each page... Joshua Moore-Oliva wrote:
Try this function... it's one part of a php class I've been thinking about making open-source. Give it any sql statement and a page (0 based for the page) and a number of records for a page and you are set. I've only tested this on postgresql. function pageSql( $sql, $page, $recs_per_page ) { $this->isString( '$sql', $sql ); $this->isInt( '$page', $page ); $this->isInt( '$recs_per_page', $recs_per_page ); $sql = trim( $sql ); $sql = substr( $sql, strlen( "SELECT" ) ); if ( $sql[strlen($sql)-1] != ";" ) { $sql .= ";"; } $sql = sprintf( "CREATE TEMP SEQUENCE temp_sequence;\n"
               . "CREATE TEMP TABLE temp_table AS\n"
               . "	 SELECT nextval( 'temp_sequence' ) AS temporary_idASDF, %s\n"
. "SELECT ( SELECT COUNT(*) FROM temp_table\n" . " WHERE temporary_idASDF > %d ) AS recs_remaining, \n"
               . "				* FROM temp_table\n"
. " WHERE temporary_idASDF > %d\n"
               . "    AND temporary_idASDF < %d\n"
               . "  ORDER BY temporary_idASDF;"
                              , $sql
               , ( $page + 1 ) * $recs_per_page + 1
               , $page * $recs_per_page
               , ( $page + 1 ) * $recs_per_page + 1 );
                return $sql;
} On February 12, 2003 11:58 am, Lucas Lain wrote:
Hi.. i'm new at this mailing list and you can say that i'm a newbie in Php programming :) i dont know how to pass a connection to a database between pages. I want to show the results in multiple pages with a unique connection. can anyone help me? Thanks in advance. Lucas -- Lucas Lain lainl@aconectarse.com Argentina
-- Lucas Lain lainl@aconectarse.com

« previous php.general (#135347) next »