note 16510 added to function.pg-fetch-object
| From: | dan at foozio dot com | Date: | Fri, 02 Nov 2001 11:10:02 +0000 |
| Subject: | note 16510 added to function.pg-fetch-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20296@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.
--
http://www.php.net/manual/en/function.pg-fetch-object.php
http://master.php.net/manage/user-notes.php?action=edit+16510
http://master.php.net/manage/user-notes.php?action=delete+16510
http://master.php.net/manage/user-notes.php?action=reject+16510