note 61054 deleted from function.mysql-fetch-row by bjori

From: Date: Tue, 25 Apr 2006 19:15:21 +0000
Subject: note 61054 deleted from function.mysql-fetch-row by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-109680@lists.php.net to get a copy of this message
Note Submitter: pbrisson at gmail dot com ---- I'm used to Microsoft-like dataset, 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

« previous php.notes (#109680) next »