note 55297 deleted from function.mysqli-error by hholzgra

From: Date: Sat, 29 Sep 2007 10:40:57 +0000
Subject: note 55297 deleted from function.mysqli-error by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130915@lists.php.net to get a copy of this message
Note Submitter: paul ate santasoft doit com ---- 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!!!!!!'); } ?>

« previous php.notes (#130915) next »