Laundry, interception of mysql errors (php?)



  • $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;
    

    $er=mysqli_error($ddb); return the empty line. But there's a mistake.

    Number of elements in type definition string doesn't match number of bind variables in...


    $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 follow-up process return NULL
    show warnings dump /var/www/html/user.php:94:null

    How do you get a report of an error in the variable? And why show warnings and mysqli_error($ddb); "not working"?



  • mysqli_error($ddb); it'll probably make mistakes, if any, in mysql request. You're making mistakes at the request level. And if you fix it, the problem will be solved. But I answer the question of how to intercept mistakes:

    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/Y H:i:s') . " WARNING : " . $errstr . PHP_EOL, 3, confGeneral::PATH_LOG.$filename);
        }
    


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2