Databases Reference
In-Depth Information
reports all errors except those in the insignificant
NOTICE
class. Your PHP installation
may be configured differently.
If you find that you're not seeing PHP error messages, you can find the
php.ini
file and
ensure that it contains the line:
display_errors = On
Add this line if necessary. Whenever you make a change to the
php.ini
file, you should
restart the Apache web server to put the changes into effect. To ensure that all errors
are reported, make sure the
error_reporting
line in
php.ini
file is set to:
error_reporting = E_ALL
and restart Apache.
If you don't have control of the web server (for example, on a web-hosting site), you
won't be able to modify the
php.ini
file. You can instead enable error reporting by
adding the two lines:
ini_set("display_errors", true);
error_reporting(E_ALL);
to the top of each PHP file, just after the PHP opening tag (
<?php
). There's no harm in
doing this even if the PHP configuration is suitable, and it allows your scripts to be
portable independent of the PHP settings on the web server.
When you're ready to deploy, turn off
display_errors
or change
error_reporting
to a
setting that won't show the user minor (or perhaps, at your discretion, any) internal
error messages. For example, you can use:
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
to force PHP to display only critical error messages. You'll find a description of the
error-setting choices at
http://www.php.net/error_reporting
.
Throughout the rest of this topic, we assume your PHP installation is configured to
report all errors, or at least everything more serious than a notice.
Accessing MySQL Using PHP
Because this topic is about MySQL, this chapter focuses on how to use PHP to access
a MySQL database. Since the release of MySQL 4.1, there have been two PHP libraries
that you can use: the original MySQL library and the MySQL Improved (MySQLi)
library.
This creates a dilemma: which library should you use? If you're working on legacy code
or a MySQL server older than version 4.1, you may not have a choice and will need to
use the original library. If you're developing new code, you do have a choice: you can
go with the original MySQL library that most developers still understand and use, or
the MySQLi library that has additional features and better performance. We recom-