Error Handling

Error handling, which is important in any script, is even more of an issue when dealing with databases since the probability for errors will increase dramatically. Common errors you will encounter are

  • Failure in connecting to a database

  • Failure in selecting a database

  • Inability to run a query

  • No results being returned by a query

Experience will teach you why these errors normally occur, but immediately seeing what the problem is when running your scripts can save you much debugging time. To have your scripts give informative reports about errors that occur, you make use of the mysql_error() and mysql_errno() functions. The former will print a textual version of the error that MySQL returned and the latter will return the corresponding ...

Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.