June 2017
Intermediate to advanced
536 pages
9h 49m
English
Handling errors around PDO can be done using the special PDOException class, as follows:
<?phptry { $host = '127.0.0.1'; $dbname = 'sakila'; $username = 'root'; $password = 'mL08e!Tq'; $conn = new PDO( "mysql:host=$host;dbname=$dbname", $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] );} catch (PDOException $e) { echo $e->getMessage(), PHP_EOL;}
There are three different error modes:
Here, we are using ERRMODE_EXCEPTION in order to utilize the try...catch blocks.
Read now
Unlock full access