Last active
August 29, 2015 14:27
-
-
Save kurozumi/5e80ed8abb5d63ddba9e to your computer and use it in GitHub Desktop.
mysqliでエラーが発生した時、例外を投げさせる方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// エラーが発生したときに、警告を発するのではなくmysqli_sql_exceptionをスローするよう設定 | |
mysqli_report(MYSQLI_REPORT_STRICT); | |
try { | |
$connection = new mysqli('localhost', 'my_user', 'my_password', 'my_db') ; | |
} catch (Exception $e ) { | |
echo "message: " . $e->message; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment