Check codeigniter query errors instead of showing them to the user

前端 未结 3 1028
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 12:04

How can I check if a query went wrong instead of showing errors to users (containing database info which is unsafe).

Let\'s say I have such situation where my paging

相关标签:
3条回答
  • 2020-12-09 12:41

    You can try this $this->db->error(); , this will get you the ErrorCode & Errormessage in array format.

    0 讨论(0)
  • 2020-12-09 12:50

    you could check it like:

    function myFunction() {
      echo 'Oeps';
    }
    
    $res = mysql_query($sql);
    if($res && mysql_num_rows($res)>0){
      echo 'Success';
    } else {
       myFunction();
    }  
    
    0 讨论(0)
  • 2020-12-09 12:56

    In application/config/database.php set

    // suppress error output to the screen
    $db['default']['db_debug'] = FALSE;
    

    In your model or controller:

    // try the select.
    $dbRet = $this->db->select($table, $dataArray);
    // select has had some problem.
    if( !$dbRet )
    {
       $errNo   = $this->db->_error_number();
       $errMess = $this->db->_error_message();
       // Do something with the error message or just show_404();
    }
    
    0 讨论(0)
提交回复
热议问题