|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-07-06 05:03 UTC] dan at novapulsar dot com
Description:
------------
Since mysql_error() is documented to 'return' a string, I assumed it would be safe to put it in either a string, or as an argument to an error handling function.
Reproduce code:
---------------
function fn_Save_Error ($x_page_url, $x_error) {
if (strlen($x_page_url) && strlen($x_error)) {
//output if debugging is on
echo ("Error on page: " . $x_page_url . " -> " . $x_error);
//save to db
}
}
$strSQL = "select all from something will make an error duh";
$objResult = mysql_query ($strSQL) or die (fn_Save_Error('this.php', mysql_error());
Expected result:
----------------
Expected result is that the string value of mysql_error() is passed as an argument of datatype string whether blank or with contents to the fn_Save_Error function.
Actual result:
--------------
Mysql_error() is output directly to the screen/console, instead of being passed as a value to fn_Save_Error for custom error handling.
Based on the mysql_error() documentation it should not output the error to screen, it should return it as a string, so that I could do this:
...some wrong query execution...
$error_message = mysql_error(); echo ($error_message);
$error_message should be == to $mysql_error, but instead it just outputs to screen/console
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 09:00:02 2025 UTC |
<?php //connect to valid mysql server mysql_connect ("localhost", "user", "password") or die (mysql_error()); mysql_select_db ("mysql") or die (mysql_error()); /* db doesn't really matter because we're trying to raise an error based on an invalid query */ $strSQL = "select all from nothing this is broken"; $objResult = mysql_execute ($strSQL) or die (fn_Save_Error ('this.php', mysql_error())); /*i expect to see the string generated by the save error function, mysql_error() as a parameter. instead, the 'return' of mysql_error goes directly to the screen, instead of being passed as a parameter as it is documented*/ function fn_Save_Error ($x_page_url, $x_error) { if (strlen($x_page_url) && strlen($x_error)) { //output if debugging is on echo ("Error on page: " . $x_page_url . " -> " . $x_error); //save to db } } ?>