LoginSignup
0
1

More than 5 years have passed since last update.

mysqliでクエリエラーを出力するようにする

Posted at

ログを見に行くのが面倒で画面に出力して欲しくなったので。

やり方

mysqli_reportを使う。

mysqli_report(MYSQLI_REPORT_ERROR);

// テーブル名をtypoしている。正しくはinformation
$mysqli->query('select * from infomation where info_id = 1');

これを実行すると下記の警告を出力してくれる。

Warning: mysqli::query(): (42S02/1146): Table 'test.infomation' doesn't exist in /Applications/MAMP/htdocs/index.php on line 11

蛇足

MYSQLI_REPORT_INDEXを追加するとインデックス未使用時に警告が出るようになります。

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_INDEX);
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1