How to identify a MySQL query problem


Sometimes you happen to have a problem with one of your MySQL queries and you simply can’t seem to understand why.

Well, one thing that helps is to use the mysql_error() function.

This function returns the message of the MySQL error you’re getting.

Example:

$action = “INSERT INTO table (name, address, dob) VALUES (‘$name’, ‘$address’, ‘$dob’)”;
$query = mysql_query($action) or die(mysql_error());

If we happen to get a problem with our MySQL error the script execution will stop (by using the die() function) and the MySQL error message will be returned (by using the mysql_error() function).

  • email
  • Add to favorites
  • Facebook
  • Twitter
  • MySpace
  • del.icio.us
  • LinkedIn
  • Digg
  • StumbleUpon
  • Google Bookmarks
  • Yahoo! Buzz
  • IndianPad
  1. No comments yet.
(will not be published)

  1. No trackbacks yet.