note 61054 added to function.mysql-fetch-row

From: Date: Tue, 24 Jan 2006 15:43:00 +0000
Subject: note 61054 added to function.mysql-fetch-row
Groups: php.notes 
Request: Send a blank email to php-notes+get-102372@lists.php.net to get a copy of this message
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 ---- Server IP: 66.207.199.35 Probable Submitter: 24.37.188.9 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-row.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61054 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61054&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61054&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102372) next »