note 58419 added to function.mysql-fetch-array

From: Date: Thu, 03 Nov 2005 18:58:31 +0000
Subject: note 58419 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-98033@lists.php.net to get a copy of this message
mob AT stag DOT ru has a nice function for getting simple arrays from MySQL but it has a serious bug. The MySQL link being set as an argument is NULL when no link is supplied meaning that you're passing NULL to the mysql funcctions as a link, which is wrong. I am not using multitple connections so I removed the link and using the global link. If you want to support multiple links check to see if its set first. /* * to support multiple links add the $link argument to function then * test it before you use the link * * if(isset($link)) * if($err=mysql_errno($link))return $err; * else * if($err=mysql_errno())return $err; */ function mysql_fetch_all($query){ $r=@mysql_query($query); if($err=mysql_errno())return $err; if(@mysql_num_rows($r)) while($row=mysql_fetch_array($r))$result[]=$row; return $result; } function mysql_fetch_one($query){ $r=@mysql_query($query); if($err=mysql_errno())return $err; if(@mysql_num_rows($r)) return mysql_fetch_array($r); } ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58419 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58419&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58419&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98033) next »