dongmeba4877 2016-10-03 22:51
浏览 79
已采纳

php mysql错误处理在错误页面中显示错误

$postQuery = $conn->query("SELECT * from table_name order by column desc")or die(mysql_error());

When there is error in query it ends the control and shows the error message in same page..

i want to redirect to an error page when error occurs and display the error in that page.

here is my Code :

$conn = new mysqli($host, $user, $password, $database);
    if ($conn->connect_error) {
        header("Location: ".SITEURL."/error.php?message=" . url_encode($conn->connect_error));
    } 

Any Suggestion.

  • 写回答

3条回答 默认 最新

  • duan02143 2016-10-03 23:07
    关注

    When your mysql query fails, it returns a False, and the connection holds the error data, which you can reference as such:

    if (!$conn->query("SELECT * from table_name order by column desc")) {
      header("Location: http://www.yoursite.com/error.php?errormessage=" . url_encode($conn->error));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部