note 49322 added to function.mysql-fetch-array

From: Date: Mon, 24 Jan 2005 07:16:11 +0000
Subject: note 49322 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-83856@lists.php.net to get a copy of this message
I wrote some utility functions to improve usability and readability, and use them everywhere in my code. I suppose they can help. function mysql_fetch_all($query,$MySQL=NULL){ $r=@mysql_query($query,$MySQL); if($err=mysql_errno($MySQL))return $err; if(@mysql_num_rows($r)) while($row=mysql_fetch_array($r))$result[]=$row; return $result; } function mysql_fetch_one($query,$MySQL=NULL){ $r=@mysql_query($query,$MySQL); if($err=mysql_errno($MySQL))return $err; if(@mysql_num_rows($r)) return mysql_fetch_array($r); } Example use: if(is_array($rows=mysql_fetch_all("select * from sometable",$MySQL))){ //do something }else{ if(!is_null($rows)) die("Query failed!"); } ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49322 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49322&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49322&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49322&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49322&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49322&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49322&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83856) next »