The first thing you want change is the mysql* functions, they are depreciated. http://www.php.net/mysql_select_db
You want to use PDO for your database connections in PHP: http://php.net/pdo
try {
$pdo = new PDO('mysql:host=localhost;dbname=test;', 'user', 'pass');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->prepare('INSERT INTO DoesNotExist (x) VALUES (?)');
}
catch(Exception $e) {
echo 'Exception -> ';
var_dump($e->getMessage());
}
Example error: Exception -> string(91) "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.doesnotexist' doesn't exist"