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.

    评论

报告相同问题?

悬赏问题

  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真