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