duandiaoqian5795 2017-02-15 05:20
浏览 9

将数据库错误重新插入数据库

What I was trying to do is inserting all query errors into a database, but, it doesnt work. I wanted to do this:

<?php
include('db_settings.php');

$query = $conn->query("mysql_query here");

if (!query) {
    $error = $conn->error;
    $log_error = $conn->query("INSERT INTO tab (log) VALUES ('$error')");
}
?>

However, this does not work, the error is not being submitted into the db. Does any of you know some workaround for this?

(before someone asks, all parameters of DB and variables are correct).

  • 写回答

1条回答 默认 最新

  • dongtang1966 2017-02-15 05:24
    关注

    You simply shouldn't do that.

    Do not try to use a medium that failed you that very instant!

    Let's take one of your recent questions: The very error message that troubled you here, Mysqli Commands out of sync will prevent your wunderlogging from functioning! Your database won't get back to sync by magic! And thus will effectively prevent you from logging its own error. And so you simply will never have an idea it occurred.

    Let errors to be logged, and then you'll be able find them all.

    add these three lines at the top of your code,

    ini_set('log_errors',1);
    error_reporting(E_ALL);
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    

    and then check the server error log.

    This is how everyone is doing it and there is no reason to devise such an awkward and illogical device.

    评论

报告相同问题?