dronebraindeveloper at gmail dot com (2013-01-01 01:37:35)
Quick note on how to setup and use mysqli_sql_exceptions properly
<?php
define("MYSQL_CONN_ERROR", "Unable to connect to database.");
// Ensure reporting is setup correctly
mysqli_report(MYSQLI_REPORT_STRICT);
// Connect function for database access
function connect($usr,$pw,$db,$host) {
try {
$mysqli = new mysqli($host,$usr,$pw,$db);
$connected = true;
} catch (mysqli_sql_exception $e) {
throw $e;
}
}
try {
connect('username','password','database','host');
echo 'Connected to database';
} catch (Exception $e) {
echo $e->errorMessage();
}
?>