dppb79372 2019-07-30 19:00
浏览 101
已采纳

无法沉默mysqli电话[关闭]

I have been trying to convert code over to using mysqli prepared statements (Converting from mysqli to prepared statements). I have the following code which I can not silence the error message from the call. Instead it is spitting out the "PHP Fatal error: ..." which halts the script so the error code is not executing but because the error is spitting out, only the header is being shown to the user.

Also note, I was attempting to also convert over to using the native php error handling as described by 'Your Common Sense' in the referenced post, but reverted back to the traditional "if (! ...) {...}" style of code due to issues not mentioned by that person (by doing that conversion). All of these modifications have been reversed that I can see.

Now for the code (and note that there is an intentional misnaming of the DB table to throw an error for checking of the code)...

$SQL = "SELECT * FROM Issues2 WHERE id=? AND disabled='0' LIMIT 1";
if (! $PRE = @mysqli_prepare($linkDB, $SQL)) {
    echo "<f><msg>ERROR: Could not prepare query: ".$SQL.", ".mysqli_error($linkDB)."</msg></f>";
} else {
    ...
}

I have tried calling the mysqli_prepare() call with and without the prepended '@' symbol, but no luck... I should be getting the "ERROR: Could not prepare ..." message, but instead I just get the XML header alone. Any help would be appreciated!

  • 写回答

1条回答 默认 最新

  • dsedug8644 2019-07-31 15:58
    关注

    You must be using

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    

    to enable automatic error reporting from mysqli functions; otherwise, they just return a falsey value and you have to check for this in your code. Unlike built-in PHP functions, @ doesn't suppress these error reports.

    Use

    mysqli_report(MYSQLI_REPORT_OFF);
    // do stuff with explicit error checking
    // ...
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    

    if you want to temporarily disable this. Or remove the above call if you want to revert to explicit error checking everywhere.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示