note 69498 deleted from function.mysql-fetch-row by bjori
| From: | bjori@php.net | Date: | Thu, 07 Sep 2006 22:37:35 +0000 |
| Subject: | note 69498 deleted from function.mysql-fetch-row by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116877@lists.php.net to get a copy of this message | ||
Note Submitter: pbrisson at gmail dot com
Reason: was this intended to be a joke
----
(Thanks to Victor Ocampo for his comment quoting me. Here's the original comment, for those who
want the function...)
I'm used to dataset objects, so I've made this function to parse mysql results, instead of
using mysql_fetch_row... It may not be fast, but since I'm often using the same data all over
my scripts, I just need to run it once.
<?
function dataset($sql)
{
global $SQL_HOST, $SQL_USER, $SQL_PASS, $SQL_DB;
@$link = mysql_connect($SQL_HOST, $SQL_USER, $SQL_PASS);
if (!$link)
{
die("Database error: " . mysql_error() . "<br><br>Please
contact admin.");
}
mysql_select_db($SQL_DB);
$result = mysql_query($sql, $link);
for($i=0;$i<mysql_num_rows($result);$i++)
{
$datapool[$i] = mysql_fetch_row($result);
}
mysql_close($link);
return $datapool;
}
?>
So I can call it this way:
<?
$dataset = dataset("SELECT * FROM employees");
?>
And to retrieve, let's say the 3rd field of the 2nd row, I use:
<?
$value = $dataset[1][2];
?>
Pierre-Yves Lapointe Brisson