All done? Nope, not quite yet - before you go out there and start building cool data-driven Web sites for your customers, you should be aware that PHP comes with some powerful error-tracking functions which can speed up development time. Take a look at the following example, which contains a deliberate error in the SELECT query string:
$connection = mysql_connect("localhost", "test", "test")
server or user");
mysql_select_db("php101",$connection) or die("Invalid
$query = "select from url_list";
$result = mysql_query($query,$connection);
$error_number = mysql_errno();
$error_msg = mysql_error();
error $error_number: $error_msg";
And here's the output:
MySQL error 1064: You have an error in your SQL syntax near
The mysql_errno() function displays the error code returned by mySQL if there's
an error in your SQL statement, while the mysql_error() function returns the actual error message. Turn these both on, and you'll find that they can significantly reduce the time you spend fixing bugs.
And that's about all we have for this issue of PHP 101. Next week, we'll be wrapping things up with a look at PHP's file read/write capabilities, and we'll also show you how to define your own PHP functions. Don't miss it!