a more eloquent PostgreSQL/PHP version of MySQL/PHP routine
| From: | Dave VanAuken | Date: | Sun, 03 Dec 2000 19:41:11 +0000 |
| Subject: | a more eloquent PostgreSQL/PHP version of MySQL/PHP routine | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-4987@lists.php.net to get a copy of this message | ||
# the following has worked well with MySQL.
# assume $database contains previously designated connection.
$query = "select * from something";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)) {
do {
# do whatever with your row
} while ($row = mysql_fetch_array($result));
}
# using the same syntax causes a number of errors with PostgreSQL.
# have had to resort to the following.
# assume $database contains previously designated connection.
$query = "select * from something";
$result = pg_exec($database,$query);
if(pg_numrows($result)>0) {
$tbNumRows=pg_numrows($result);
$tbCount=0;
while($tbCount<$tbNumRows) {
$row = pg_fetch_array($result,$tbCount); # or could use fetch row
# do whatever with your row/result
$tbCount++;
}
}
# would appreciate any insight into streamlining the PostgreSQL code a
little more