PHP & MySQL: The Missing Manual
Example 5-1
SQL Connection test