Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/5e80ed8abb5d63ddba9e to your computer and use it in GitHub Desktop.
Save kurozumi/5e80ed8abb5d63ddba9e to your computer and use it in GitHub Desktop.
mysqliでエラーが発生した時、例外を投げさせる方法
<?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