note 34377 added to function.mysql-error
| From: | scott at rocketpack dot net | Date: | Fri, 25 Jul 2003 07:44:12 +0000 |
| Subject: | note 34377 added to function.mysql-error | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52617@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...
<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
----
Manual Page -- http://www.php.net/manual/en/function.mysql-error.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34377
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34377&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34377&report=yes