$q = 'select usname,regdate_usopt,usplace,usablog,uslife,umk,usfoto,usdes,uslevel,usoffst,lact from usopt join act on uid_usopt=uid_act where uid_usopt=?'; $rawdata = mysqli_prepare($ddb, $q); //qres('prep', $rawdata, $ddb); $res = mysqli_stmt_bind_param($rawdata, 'di', $uid); $err=mysqli_error($ddb); echo "mysqli_error = $err<br>"; exit; 

$ err = mysqli_error ($ ddb); returns an empty string. But there is an error. Bind variables


 $q = 'select usname,regdate_usopt,usplace,usablog,uslife,umk,usfoto,usdes,uslevel,usoffst,lact from usopt join act on uid_usopt=uid_act where uid_usopt=?'; $rawdata = mysqli_prepare($ddb, $q); //qres('prep', $rawdata, $ddb); $res = mysqli_stmt_bind_param($rawdata, 'di', $uid); //$err=mysqli_error($ddb); //echo "mysqli_error = $err<br>"; //exit; $q = 'show warnings'; $sq_data = mysqli_query($ddb, $q); //SimpleQuery_data //var_dump($sq_data); $x = mysqli_num_rows($sq_data); $data = mysqli_fetch_row($sq_data); //SimpleQuery_data echo 'show warnings dump<br>'; var_dump($data); exit; 

$ q = 'show warnings'; and subsequent processing returns NULL show warnings dump /var/www/html/user.php:94:null

How to get an error message in a variable? And why show warnings and mysqli_error ($ ddb); "does not work"?

  • 2
    It is much better to use PDO and catch PDOException using try-catch - ilyaplot
  • ilyaplot, it is much better not to write curve queries and then there will be nothing to catch. - koks_rs
  • In general, when requesting a database there should be no Vornigov. If they are, then you need to think about how to make them out, and write to the logs only for debugging unless. - koks_rs pm
  • for debugging it is necessary that everything is good in the working base and code. And the setting of the hour varing modet can be due to trimming or nonconformance of fields in TB and data. it needs to be caught. - root_x Povierennyy
  • I already understand everything: these are syntax errors. And now sometimes they slip. - root_x Povierennyy

1 answer 1

mysqli_error ($ ddb); apparently returns errors, if any, in a mysql query. You have the same errors at the query assembly level. And if you fix it the problem will be solved. But I will answer the question how to intercept errors:

 set_error_handler("MyClass::myWarning_handler", E_WARNING | E_STRICT); //тут ваш код кот вызывает ошибки //вернуться к состяюнию по умолчанию restore_error_handler(); 

...

  //confGeneral::PATH_LOG - переменная кот хранит путь к логам //$errstr -это ваша ошибка в переменной function myWarning_handler($errno, $errstr) { if (!is_dir(confGeneral::PATH_LOG)) { mkdir(confGeneral::PATH_LOG, 0777, true); } $filename = "mailErrors.log"; error_log(date('d/m/YH:i:s') . " WARNING : " . $errstr . PHP_EOL, 3, confGeneral::PATH_LOG.$filename); }