1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

How can report MySQL errors into PHP?

By

Man using laptop
Robert Daly/OJO Images/Getty Images
Question: How can report MySQL errors into PHP?
How can I receive feedback from MySQL when my PHP encounters a problem?

Answer: When you are working with PHP and MySQL and encounter an error, it is helpful to receive more detailed information regarding the problem to point you in the direction of fixing it. You can use the mysql_error ( ) to get feedback from MySQL to your PHP document if you are encountering problems. It is phrased as: mysql_error ( [link_identifier] )

Here are some examples of how to utilize mysql_error ()

mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) 
This will return an error if there is a problem connecting to your MySQL database

 $value = mysql_query($your_query) or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error())
When you encounter an error, this will return your custom message (A MySQL error has occurred.<br />) followed by a line number, and the actual error.
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. PHP with MySQL
  5. Report MySQL Errors Into PHP

©2014 About.com. All rights reserved.