note 48698 modified in function.mysql-error by felipe
| From: | felipe@php.net | Date: | Sun, 15 Jun 2008 12:10:21 +0000 |
| Subject: | note 48698 modified in function.mysql-error by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140467@lists.php.net to get a copy of this message | ||
My suggested implementation of mysql_error():
$result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br
/>Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " .
mysql_error());
This will print out something like...
A fatal MySQL error occured.
Query: SELECT * FROM table
Error: (err_no) Bla bla bla, you did everything wrong
It's very useful to see your query in order to detect problems with syntax. Most often, the
output message from MySQL doesn't let you see enough of the query in the error message to let
you see where your query went bad- it a missing quote, comma, or ( or ) could have occured well
before the error was detected. I do -not- recomend using this procedure, however, for queries which
execute on your site that are not user-specific as it has the potential to leak sensative data.
Recomended use is just for debugging/building a script, and for general user-specific queries which
would at the worst, leak the users own information to themself.
Good luck,
-Scott
--was--
My suggested implementation of mysql_error():
$result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br
/>Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " .
mysql_error());
This will print out something like...
<b>A fatal MySQL error occured</b>.
Query: SELECT * FROM table
Error: (err_no) Bla bla bla, you did everything wrong
It's very useful to see your query in order to detect problems with syntax. Most often, the
output message from MySQL doesn't let you see enough of the query in the error message to let
you see where your query went bad- it a missing quote, comma, or ( or ) could have occured well
before the error was detected. I do -not- recomend using this procedure, however, for queries which
execute on your site that are not user-specific as it has the potential to leak sensative data.
Recomended use is just for debugging/building a script, and for general user-specific queries which
would at the worst, leak the users own information to themself.
Good luck,
-Scott
http://php.net/manual/en/function.mysql-error.php