Skip to content

Instantly share code, notes, and snippets.

@kurozumi

kurozumi/mysqli_report.php

Last active Aug 29, 2015
Embed
What would you like to do?
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