MySQLi和PHPs error_handler

时间:2019-05-31 12:19:00

标签: php mysqli

以下是一些(简化的)代码:

function error_handler($errno, $errstr, $errfile, $errline){    

    $mysqli_log = new mysqli('host', 'user', 'pass', 'db');

    $mysqli_log->query("INSERT INTO logging (log, lognr) VALUES ('" . $errno . "', '" . $errstr . "')");

    return TRUE;

}

set_error_handler("error_handler", E_ALL);


$mysqli_master = new mysqli("123.456.789.123", "user123", "password123", "my_db"));

var_dump($mysqli_master);

为了进行测试,我为连接$ mysqli_master输入了错误的数据。 禁用set_error_handler()后,我从var_dump()获得了预期的回报。类似这样的东西:

(设置了“ connect_errno”和“ connect_errno”)

object(mysqli)#1 (19) {
  ["affected_rows"]=>  NULL
  ["client_info"]=>  NULL
  ["client_version"]=>  int(50012)
  ["connect_errno"]=>  int(1130)
  ["connect_error"]=>  string(68) "Host '....' is not allowed to connect to this MySQL server"
  ["errno"]=>  NULL
  ["error"]=>  NULL
  ["error_list"]=>  NULL
  ["field_count"]=>  NULL
  ["host_info"]=>  NULL
  ["info"]=>  NULL
  ["insert_id"]=>  NULL
  ["server_info"]=>  NULL
  ["server_version"]=>  NULL
  ["stat"]=>  NULL
  ["sqlstate"]=>  NULL
  ["protocol_version"]=>  NULL
  ["thread_id"]=>  NULL
  ["warning_count"]=>  NULL

启用set_error_handler()后,我得到以下信息:

object(mysqli)#1 (19) {
  ["affected_rows"]=>  NULL
  ["client_info"]=>  NULL
  ["client_version"]=>  int(50012)
  ["connect_errno"]=>  int(0)
  ["connect_error"]=>  NULL
  ["errno"]=>  NULL
  ["error"]=>  NULL
  ["error_list"]=>  NULL
  ["field_count"]=>  NULL
  ["host_info"]=>  NULL
  ["info"]=>  NULL
  ["insert_id"]=>  NULL
  ["server_info"]=>  NULL
  ["server_version"]=>  NULL
  ["stat"]=>  NULL
  ["sqlstate"]=>  NULL
  ["protocol_version"]=>  NULL
  ["thread_id"]=>  NULL
  ["warning_count"]=>  NULL
}

以某种方式,错误处理程序功能内的mysqli连接正在覆盖$ mysqli_master-connection。

有什么想法吗?

0 个答案:

没有答案