Вопрос

I have a mysqli_query that goes like this:

$result = mysqli_query($db, "INSERT INTO device(`Identifier`, `IsAllowedToPost`)
VALUES('ABC123', 0)") or die(error_log(mysqli_error($db), 3, "php_error.log"));

It does not work and the logs either tells me "1", "0" or nothing depending on which method I try to log the error with. How can I get a better error message to log in my file? I have no idea what 0 or 1 means.

The current code gives me no error message at all in my file and the test data does not get stored in the database.

Это было полезно?

Решение

change your code like this

ini_set('log_errors',1);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
mysqli_connect(credentials);
...
$result = mysqli_query($db, "INSERT INTO device(`Identifier`, `IsAllowedToPost`)
VALUES('ABC123', 0)");

and watch your mysql errors in php error log.

Code you wrote is suffering from some wrong premises.

  1. You apparently need to log ALL errors occurred in your code, not only mysql-related ones. Such a separation makes no sense. So, you need a common log.
  2. You don't need to write distinct code for the every query. Mysqli is smart enough to raise an error automatically.
  3. setting error log file with relative path will result in multiple logs, according to directory structure.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top