Chapter 19. MySQL Gotchas

This chapter details some of the common difficulties that arise with using PHP and databases. The goal is to help you diagnose and solve problems more quickly and with less frustration. As usual, our specific code and function references are to MySQL (with one exception), although the set of gotchas is fairly independent across different databases.

Note

This chapter is about diagnosing and fixing PHP/database code that is genuinely broken — that is, it is not successfully retrieving data, or it is producing error messages. If your scripts are working, but too slowly, see Chapter 18.

No Connection

If you have a database call in your PHP script and the connection can't be opened, you will see a version of one of these two warning screens (depending on how high your error reporting levels are cranked up, and, to some extent, the precise cause of the problem).

The first possibility is the No Connection warning, as shown in Figure 19-1.

This option indicates a problem either with the MySQL server itself or with the path to mysqld. In its own special way, PHP is telling you that it knows about MySQL but can't hook up to it. This is the error you will see on a working PHP-MySQL installation if the database server crashes.

If the problem is on the PHP side, your error screen will look more like the one shown in Figure 19-2 ...

Get PHP6 and MySQL® 6 Bible 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.