note 55297 added to function.mysqli-error

From: Date: Fri, 29 Jul 2005 13:50:15 +0000
Subject: note 55297 added to function.mysqli-error
Groups: php.notes 
Request: Send a blank email to php-notes+get-92725@lists.php.net to get a copy of this message
When migrating to PHP 5 from PHP 4, an important sticky note on the brain: PHP 4 would default to the current connection (last opened connection) with mysql_error(). PHP 5 & mysqli, on the other hand, requires the link to be specified as in mysqli_error($link). So if you are migrating and get a blank screen and don't know why, check your mysqli_* statements to ensure they include the $link if needed. examples: PHP 4: <?php $link = mysql_connect('localhost',''uid','pw'); $sql = 'some bad query'; $result = mysql_query($sql); if (!mysql_num_rows($result)) { echo(mysql_error()); } else { echo('It Worked!!!!!!'); } ?> PHP 5: <?php $link = mysqli_connect('localhost',''uid','pw'); $sql = 'some bad query'; $result = mysqli_query($link,$sql); // remember to include the link on queries too if (!mysqli_num_rows($result)) { echo(mysqli_error($link)); // aha! } else { echo('It Worked!!!!!!'); } ?> ---- Submitter IP: 64.71.164.2 ---- Manual Page -- http://www.php.net/manual/en/function.mysqli-error.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55297 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55297&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55297&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55297&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55297&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55297&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55297&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55297&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92725) next »