I am connecting to MySQL database on my webpage and have this copy-pasted code for errors:
if(DB::isError($db)) die($db->getMessage());
I have the connection code in an outside file called connection.inc that I include at the beginning of my page before the DOCTYPE and html tags.
For debugging purposes, how can I print the database errors on my webpage?
I thought I could do something like this:
echo 'Could not connect to database. The error was:' . $db->getMessage();
but this returns: Fatal error: Call to undefined method DB_mysql::getMessage()
The connection.inc looks like this:
require_once("DB.php");
$dsn="mysql://mannerv_bonus:blahblah@localhost/mannerv_bonus";
$db = DB::connect($dsn);
if(DB::isError($db)) die($db->getMessage());
else $db->query("SET NAMES 'latin1'");
I tried this:
if(DB::isError($db)) {
echo 'There was an error';
echo $db->getMessage();
}
I can change the password and do whatever but it seems that the isError is never true. I thought that if the password is wrong, this would be an error.