note 16510 deleted from function.pg-fetch-object by jimw

From: Date: Fri, 02 Nov 2001 17:15:09 +0000
Subject: note 16510 deleted from function.pg-fetch-object by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20307@lists.php.net to get a copy of this message
Here is a function to make returning row objects more like mysql_fetch_object(): $row = 0; // Make a row an object function db_fetch_object($result_id) { GLOBAL $row; $re = @pg_fetch_object($result_id,$row); if($re){ // Used for the next call $row++; // Return the object return $re; }else{ // Reset the row counter for the next query $row = 0; // Return false return 0; } } // Run the query $sql = "SELECT * FROM table"; $result_id = pg_exec($conn,$sql); // Loop through the results while($f = db_fetch_object($result_id)) { echo "$f->field1 $f->field2<br>"; } Should work for procedural code. The $row variable will conflict if different queries are called out of sequence or one result is embedded in another.

« previous php.notes (#20307) next »