Codeigniter : $this->db->_error_message() message returns NULL












2















I have a query which gives me perfect results. But I need to send the mysql errors (if any) to UI. So I deliberately change column name to blah_text.



$qID = 13
$this->db->select('id AS optionID, blah_text AS option, is_correct AS isCorrect');
$oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));
if($oQuery){
$qnaArray['options'] = $oQuery->result_array();
}
else{
//$qnaArray['error'] = $this->db->_error_message();
echo "Error: " . $this->db->_error_message();
}


All the get is Error:



I tried using native mysqli function mysqli_error($oQuery); but same O/P



Note: I have set 'db_debug' => FALSE in database config files. If I set it to TRUE, i do get the CI error message



Error Number: 1054 Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect



How do I capture sql errors in a variable and send it to UI like $qnaArray['error']



EDIT: 'db_debug' is currently set to FALSE. I want the error message to be set in a variable. Not echoed on the screen.










share|improve this question

























  • If you are getting error using 'db_debug'=> TRUE. What is the problem?

    – Sagar Khatri
    Oct 30 '15 at 13:36











  • @SagarKhatri I get errors on the page CI styled. I need to send it as a webservice json to UI so that I can be displayed properly.

    – eNeMetcH
    Oct 31 '15 at 8:46











  • Which clients are going to use your WebService? Android,iPhone or in frontend through JS?

    – Sagar Khatri
    Oct 31 '15 at 10:43











  • @SagarKhatri iPad and JS

    – eNeMetcH
    Oct 31 '15 at 10:49











  • I think stripping the tag and getting the message text will be enough. You can use $qnaArray['error'] = strip_tags($this->db->_error_message());.

    – Sagar Khatri
    Oct 31 '15 at 10:53
















2















I have a query which gives me perfect results. But I need to send the mysql errors (if any) to UI. So I deliberately change column name to blah_text.



$qID = 13
$this->db->select('id AS optionID, blah_text AS option, is_correct AS isCorrect');
$oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));
if($oQuery){
$qnaArray['options'] = $oQuery->result_array();
}
else{
//$qnaArray['error'] = $this->db->_error_message();
echo "Error: " . $this->db->_error_message();
}


All the get is Error:



I tried using native mysqli function mysqli_error($oQuery); but same O/P



Note: I have set 'db_debug' => FALSE in database config files. If I set it to TRUE, i do get the CI error message



Error Number: 1054 Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect



How do I capture sql errors in a variable and send it to UI like $qnaArray['error']



EDIT: 'db_debug' is currently set to FALSE. I want the error message to be set in a variable. Not echoed on the screen.










share|improve this question

























  • If you are getting error using 'db_debug'=> TRUE. What is the problem?

    – Sagar Khatri
    Oct 30 '15 at 13:36











  • @SagarKhatri I get errors on the page CI styled. I need to send it as a webservice json to UI so that I can be displayed properly.

    – eNeMetcH
    Oct 31 '15 at 8:46











  • Which clients are going to use your WebService? Android,iPhone or in frontend through JS?

    – Sagar Khatri
    Oct 31 '15 at 10:43











  • @SagarKhatri iPad and JS

    – eNeMetcH
    Oct 31 '15 at 10:49











  • I think stripping the tag and getting the message text will be enough. You can use $qnaArray['error'] = strip_tags($this->db->_error_message());.

    – Sagar Khatri
    Oct 31 '15 at 10:53














2












2








2


1






I have a query which gives me perfect results. But I need to send the mysql errors (if any) to UI. So I deliberately change column name to blah_text.



$qID = 13
$this->db->select('id AS optionID, blah_text AS option, is_correct AS isCorrect');
$oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));
if($oQuery){
$qnaArray['options'] = $oQuery->result_array();
}
else{
//$qnaArray['error'] = $this->db->_error_message();
echo "Error: " . $this->db->_error_message();
}


All the get is Error:



I tried using native mysqli function mysqli_error($oQuery); but same O/P



Note: I have set 'db_debug' => FALSE in database config files. If I set it to TRUE, i do get the CI error message



Error Number: 1054 Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect



How do I capture sql errors in a variable and send it to UI like $qnaArray['error']



EDIT: 'db_debug' is currently set to FALSE. I want the error message to be set in a variable. Not echoed on the screen.










share|improve this question
















I have a query which gives me perfect results. But I need to send the mysql errors (if any) to UI. So I deliberately change column name to blah_text.



$qID = 13
$this->db->select('id AS optionID, blah_text AS option, is_correct AS isCorrect');
$oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));
if($oQuery){
$qnaArray['options'] = $oQuery->result_array();
}
else{
//$qnaArray['error'] = $this->db->_error_message();
echo "Error: " . $this->db->_error_message();
}


All the get is Error:



I tried using native mysqli function mysqli_error($oQuery); but same O/P



Note: I have set 'db_debug' => FALSE in database config files. If I set it to TRUE, i do get the CI error message



Error Number: 1054 Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect



How do I capture sql errors in a variable and send it to UI like $qnaArray['error']



EDIT: 'db_debug' is currently set to FALSE. I want the error message to be set in a variable. Not echoed on the screen.







php mysql codeigniter mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 31 '15 at 11:09







eNeMetcH

















asked Oct 30 '15 at 10:24









eNeMetcHeNeMetcH

1521215




1521215













  • If you are getting error using 'db_debug'=> TRUE. What is the problem?

    – Sagar Khatri
    Oct 30 '15 at 13:36











  • @SagarKhatri I get errors on the page CI styled. I need to send it as a webservice json to UI so that I can be displayed properly.

    – eNeMetcH
    Oct 31 '15 at 8:46











  • Which clients are going to use your WebService? Android,iPhone or in frontend through JS?

    – Sagar Khatri
    Oct 31 '15 at 10:43











  • @SagarKhatri iPad and JS

    – eNeMetcH
    Oct 31 '15 at 10:49











  • I think stripping the tag and getting the message text will be enough. You can use $qnaArray['error'] = strip_tags($this->db->_error_message());.

    – Sagar Khatri
    Oct 31 '15 at 10:53



















  • If you are getting error using 'db_debug'=> TRUE. What is the problem?

    – Sagar Khatri
    Oct 30 '15 at 13:36











  • @SagarKhatri I get errors on the page CI styled. I need to send it as a webservice json to UI so that I can be displayed properly.

    – eNeMetcH
    Oct 31 '15 at 8:46











  • Which clients are going to use your WebService? Android,iPhone or in frontend through JS?

    – Sagar Khatri
    Oct 31 '15 at 10:43











  • @SagarKhatri iPad and JS

    – eNeMetcH
    Oct 31 '15 at 10:49











  • I think stripping the tag and getting the message text will be enough. You can use $qnaArray['error'] = strip_tags($this->db->_error_message());.

    – Sagar Khatri
    Oct 31 '15 at 10:53

















If you are getting error using 'db_debug'=> TRUE. What is the problem?

– Sagar Khatri
Oct 30 '15 at 13:36





If you are getting error using 'db_debug'=> TRUE. What is the problem?

– Sagar Khatri
Oct 30 '15 at 13:36













@SagarKhatri I get errors on the page CI styled. I need to send it as a webservice json to UI so that I can be displayed properly.

– eNeMetcH
Oct 31 '15 at 8:46





@SagarKhatri I get errors on the page CI styled. I need to send it as a webservice json to UI so that I can be displayed properly.

– eNeMetcH
Oct 31 '15 at 8:46













Which clients are going to use your WebService? Android,iPhone or in frontend through JS?

– Sagar Khatri
Oct 31 '15 at 10:43





Which clients are going to use your WebService? Android,iPhone or in frontend through JS?

– Sagar Khatri
Oct 31 '15 at 10:43













@SagarKhatri iPad and JS

– eNeMetcH
Oct 31 '15 at 10:49





@SagarKhatri iPad and JS

– eNeMetcH
Oct 31 '15 at 10:49













I think stripping the tag and getting the message text will be enough. You can use $qnaArray['error'] = strip_tags($this->db->_error_message());.

– Sagar Khatri
Oct 31 '15 at 10:53





I think stripping the tag and getting the message text will be enough. You can use $qnaArray['error'] = strip_tags($this->db->_error_message());.

– Sagar Khatri
Oct 31 '15 at 10:53












4 Answers
4






active

oldest

votes


















1














$this->db->_error_message(); will not execute when selecting data.



Use this



$qID = '13';
$query = $this->db->query(
"SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect
FROM table_name WHERE xq_options = $qID");
$result = $query->result_array();
$count = count($result);

if (!empty($count)) {
return $result;
}
else{
echo "No Data Found";
}





share|improve this answer
























  • I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

    – eNeMetcH
    Oct 30 '15 at 11:01











  • Use my query and check

    – Abdulla Nilam
    Oct 30 '15 at 11:03











  • Your query works. But I either get results or I get "No Data Found", What I need is the error message.

    – eNeMetcH
    Oct 30 '15 at 11:06











  • what kind of error??

    – Abdulla Nilam
    Oct 30 '15 at 11:07











  • Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

    – eNeMetcH
    Oct 30 '15 at 11:16



















0














Instead of this:



if($oQuery)
{
$qnaArray['options'] = $oQuery->result_array();
}
else{
//$qnaArray['error'] = $this->db->_error_message();
echo "Error: " . $this->db->_error_message();
}


try using this:



if($oQuery->num_rows()>0)
{
$qnaArray['options'] = $oQuery->result_array();
}
else{
//$qnaArray['error'] = $this->db->_error_message();
echo "Error: " . $this->db->_error_message();
}





share|improve this answer
























  • I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

    – eNeMetcH
    Oct 30 '15 at 11:17













  • use this link.. stackoverflow.com/questions/17923382/…

    – Samrat Aher
    Oct 30 '15 at 11:49





















0














if (!$this->db->simple_query('SELECT `id` FROM `customers`')) {
$error = $this->db->error();
}

$data['db_error_message'] = 'Error [' . $error['code'] . '] ' . $error['message'];


From the documentation on page https://www.codeigniter.com/userguide3/database/queries.html#handling-errors



In your view, this code prints out a message like this;



DB Error Message : Error [1146] Table 'mydb.customers' doesn't exist



Similarly, your code prints out the same result.



$qID = 13;
$this->db->select('id AS `optionID`, blah_text AS `option`, is_correct AS `isCorrect`');
$oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));

if (!$oQuery) {
$err = $this->db->error();
}
$data['err_message'] = 'Error [' . $err['code'] . '] ' . $err['message'];


prints;
Err Message : Error [1146] Table 'mydb.xq_options' doesn't exist



I did not create tables, so my messages are 'table not found' error messages instead of 'column not found'.



I guess this is what you wanted.






share|improve this answer































    0














    Use



    $e = $this->db->error(); // Gets the last error that has occured
    $num = $e['code'];
    $mess = $e['message'];


    Info available in https://www.codeigniter.com/userguide3/database/queries.html search "Handling Errors"






    share|improve this answer


























    • Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

      – Ahmet Çavdar
      Oct 3 '17 at 4:01













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33433725%2fcodeigniter-this-db-error-message-message-returns-null%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    $this->db->_error_message(); will not execute when selecting data.



    Use this



    $qID = '13';
    $query = $this->db->query(
    "SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect
    FROM table_name WHERE xq_options = $qID");
    $result = $query->result_array();
    $count = count($result);

    if (!empty($count)) {
    return $result;
    }
    else{
    echo "No Data Found";
    }





    share|improve this answer
























    • I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:01











    • Use my query and check

      – Abdulla Nilam
      Oct 30 '15 at 11:03











    • Your query works. But I either get results or I get "No Data Found", What I need is the error message.

      – eNeMetcH
      Oct 30 '15 at 11:06











    • what kind of error??

      – Abdulla Nilam
      Oct 30 '15 at 11:07











    • Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:16
















    1














    $this->db->_error_message(); will not execute when selecting data.



    Use this



    $qID = '13';
    $query = $this->db->query(
    "SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect
    FROM table_name WHERE xq_options = $qID");
    $result = $query->result_array();
    $count = count($result);

    if (!empty($count)) {
    return $result;
    }
    else{
    echo "No Data Found";
    }





    share|improve this answer
























    • I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:01











    • Use my query and check

      – Abdulla Nilam
      Oct 30 '15 at 11:03











    • Your query works. But I either get results or I get "No Data Found", What I need is the error message.

      – eNeMetcH
      Oct 30 '15 at 11:06











    • what kind of error??

      – Abdulla Nilam
      Oct 30 '15 at 11:07











    • Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:16














    1












    1








    1







    $this->db->_error_message(); will not execute when selecting data.



    Use this



    $qID = '13';
    $query = $this->db->query(
    "SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect
    FROM table_name WHERE xq_options = $qID");
    $result = $query->result_array();
    $count = count($result);

    if (!empty($count)) {
    return $result;
    }
    else{
    echo "No Data Found";
    }





    share|improve this answer













    $this->db->_error_message(); will not execute when selecting data.



    Use this



    $qID = '13';
    $query = $this->db->query(
    "SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect
    FROM table_name WHERE xq_options = $qID");
    $result = $query->result_array();
    $count = count($result);

    if (!empty($count)) {
    return $result;
    }
    else{
    echo "No Data Found";
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 30 '15 at 10:57









    Abdulla NilamAbdulla Nilam

    23.9k133861




    23.9k133861













    • I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:01











    • Use my query and check

      – Abdulla Nilam
      Oct 30 '15 at 11:03











    • Your query works. But I either get results or I get "No Data Found", What I need is the error message.

      – eNeMetcH
      Oct 30 '15 at 11:06











    • what kind of error??

      – Abdulla Nilam
      Oct 30 '15 at 11:07











    • Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:16



















    • I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:01











    • Use my query and check

      – Abdulla Nilam
      Oct 30 '15 at 11:03











    • Your query works. But I either get results or I get "No Data Found", What I need is the error message.

      – eNeMetcH
      Oct 30 '15 at 11:06











    • what kind of error??

      – Abdulla Nilam
      Oct 30 '15 at 11:07











    • Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

      – eNeMetcH
      Oct 30 '15 at 11:16

















    I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

    – eNeMetcH
    Oct 30 '15 at 11:01





    I can use $query->num_rows() instead. Thats not the point. I need to see the MySQL error message. Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

    – eNeMetcH
    Oct 30 '15 at 11:01













    Use my query and check

    – Abdulla Nilam
    Oct 30 '15 at 11:03





    Use my query and check

    – Abdulla Nilam
    Oct 30 '15 at 11:03













    Your query works. But I either get results or I get "No Data Found", What I need is the error message.

    – eNeMetcH
    Oct 30 '15 at 11:06





    Your query works. But I either get results or I get "No Data Found", What I need is the error message.

    – eNeMetcH
    Oct 30 '15 at 11:06













    what kind of error??

    – Abdulla Nilam
    Oct 30 '15 at 11:07





    what kind of error??

    – Abdulla Nilam
    Oct 30 '15 at 11:07













    Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

    – eNeMetcH
    Oct 30 '15 at 11:16





    Unknown column 'blah_text' in 'field list' SELECT id AS optionID, blah_text AS option, is_correct AS isCorrect

    – eNeMetcH
    Oct 30 '15 at 11:16













    0














    Instead of this:



    if($oQuery)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }


    try using this:



    if($oQuery->num_rows()>0)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }





    share|improve this answer
























    • I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

      – eNeMetcH
      Oct 30 '15 at 11:17













    • use this link.. stackoverflow.com/questions/17923382/…

      – Samrat Aher
      Oct 30 '15 at 11:49


















    0














    Instead of this:



    if($oQuery)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }


    try using this:



    if($oQuery->num_rows()>0)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }





    share|improve this answer
























    • I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

      – eNeMetcH
      Oct 30 '15 at 11:17













    • use this link.. stackoverflow.com/questions/17923382/…

      – Samrat Aher
      Oct 30 '15 at 11:49
















    0












    0








    0







    Instead of this:



    if($oQuery)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }


    try using this:



    if($oQuery->num_rows()>0)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }





    share|improve this answer













    Instead of this:



    if($oQuery)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }


    try using this:



    if($oQuery->num_rows()>0)
    {
    $qnaArray['options'] = $oQuery->result_array();
    }
    else{
    //$qnaArray['error'] = $this->db->_error_message();
    echo "Error: " . $this->db->_error_message();
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 30 '15 at 11:09









    Samrat AherSamrat Aher

    765




    765













    • I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

      – eNeMetcH
      Oct 30 '15 at 11:17













    • use this link.. stackoverflow.com/questions/17923382/…

      – Samrat Aher
      Oct 30 '15 at 11:49





















    • I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

      – eNeMetcH
      Oct 30 '15 at 11:17













    • use this link.. stackoverflow.com/questions/17923382/…

      – Samrat Aher
      Oct 30 '15 at 11:49



















    I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

    – eNeMetcH
    Oct 30 '15 at 11:17







    I got this: Fatal error: Call to a member function num_rows() on boolean But a CI error message. Not from $this->db->_error_message();

    – eNeMetcH
    Oct 30 '15 at 11:17















    use this link.. stackoverflow.com/questions/17923382/…

    – Samrat Aher
    Oct 30 '15 at 11:49







    use this link.. stackoverflow.com/questions/17923382/…

    – Samrat Aher
    Oct 30 '15 at 11:49













    0














    if (!$this->db->simple_query('SELECT `id` FROM `customers`')) {
    $error = $this->db->error();
    }

    $data['db_error_message'] = 'Error [' . $error['code'] . '] ' . $error['message'];


    From the documentation on page https://www.codeigniter.com/userguide3/database/queries.html#handling-errors



    In your view, this code prints out a message like this;



    DB Error Message : Error [1146] Table 'mydb.customers' doesn't exist



    Similarly, your code prints out the same result.



    $qID = 13;
    $this->db->select('id AS `optionID`, blah_text AS `option`, is_correct AS `isCorrect`');
    $oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));

    if (!$oQuery) {
    $err = $this->db->error();
    }
    $data['err_message'] = 'Error [' . $err['code'] . '] ' . $err['message'];


    prints;
    Err Message : Error [1146] Table 'mydb.xq_options' doesn't exist



    I did not create tables, so my messages are 'table not found' error messages instead of 'column not found'.



    I guess this is what you wanted.






    share|improve this answer




























      0














      if (!$this->db->simple_query('SELECT `id` FROM `customers`')) {
      $error = $this->db->error();
      }

      $data['db_error_message'] = 'Error [' . $error['code'] . '] ' . $error['message'];


      From the documentation on page https://www.codeigniter.com/userguide3/database/queries.html#handling-errors



      In your view, this code prints out a message like this;



      DB Error Message : Error [1146] Table 'mydb.customers' doesn't exist



      Similarly, your code prints out the same result.



      $qID = 13;
      $this->db->select('id AS `optionID`, blah_text AS `option`, is_correct AS `isCorrect`');
      $oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));

      if (!$oQuery) {
      $err = $this->db->error();
      }
      $data['err_message'] = 'Error [' . $err['code'] . '] ' . $err['message'];


      prints;
      Err Message : Error [1146] Table 'mydb.xq_options' doesn't exist



      I did not create tables, so my messages are 'table not found' error messages instead of 'column not found'.



      I guess this is what you wanted.






      share|improve this answer


























        0












        0








        0







        if (!$this->db->simple_query('SELECT `id` FROM `customers`')) {
        $error = $this->db->error();
        }

        $data['db_error_message'] = 'Error [' . $error['code'] . '] ' . $error['message'];


        From the documentation on page https://www.codeigniter.com/userguide3/database/queries.html#handling-errors



        In your view, this code prints out a message like this;



        DB Error Message : Error [1146] Table 'mydb.customers' doesn't exist



        Similarly, your code prints out the same result.



        $qID = 13;
        $this->db->select('id AS `optionID`, blah_text AS `option`, is_correct AS `isCorrect`');
        $oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));

        if (!$oQuery) {
        $err = $this->db->error();
        }
        $data['err_message'] = 'Error [' . $err['code'] . '] ' . $err['message'];


        prints;
        Err Message : Error [1146] Table 'mydb.xq_options' doesn't exist



        I did not create tables, so my messages are 'table not found' error messages instead of 'column not found'.



        I guess this is what you wanted.






        share|improve this answer













        if (!$this->db->simple_query('SELECT `id` FROM `customers`')) {
        $error = $this->db->error();
        }

        $data['db_error_message'] = 'Error [' . $error['code'] . '] ' . $error['message'];


        From the documentation on page https://www.codeigniter.com/userguide3/database/queries.html#handling-errors



        In your view, this code prints out a message like this;



        DB Error Message : Error [1146] Table 'mydb.customers' doesn't exist



        Similarly, your code prints out the same result.



        $qID = 13;
        $this->db->select('id AS `optionID`, blah_text AS `option`, is_correct AS `isCorrect`');
        $oQuery = $this->db->get_where('xq_options', array('question_id' => $qID));

        if (!$oQuery) {
        $err = $this->db->error();
        }
        $data['err_message'] = 'Error [' . $err['code'] . '] ' . $err['message'];


        prints;
        Err Message : Error [1146] Table 'mydb.xq_options' doesn't exist



        I did not create tables, so my messages are 'table not found' error messages instead of 'column not found'.



        I guess this is what you wanted.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 3 '17 at 4:00









        Ahmet ÇavdarAhmet Çavdar

        715




        715























            0














            Use



            $e = $this->db->error(); // Gets the last error that has occured
            $num = $e['code'];
            $mess = $e['message'];


            Info available in https://www.codeigniter.com/userguide3/database/queries.html search "Handling Errors"






            share|improve this answer


























            • Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

              – Ahmet Çavdar
              Oct 3 '17 at 4:01


















            0














            Use



            $e = $this->db->error(); // Gets the last error that has occured
            $num = $e['code'];
            $mess = $e['message'];


            Info available in https://www.codeigniter.com/userguide3/database/queries.html search "Handling Errors"






            share|improve this answer


























            • Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

              – Ahmet Çavdar
              Oct 3 '17 at 4:01
















            0












            0








            0







            Use



            $e = $this->db->error(); // Gets the last error that has occured
            $num = $e['code'];
            $mess = $e['message'];


            Info available in https://www.codeigniter.com/userguide3/database/queries.html search "Handling Errors"






            share|improve this answer















            Use



            $e = $this->db->error(); // Gets the last error that has occured
            $num = $e['code'];
            $mess = $e['message'];


            Info available in https://www.codeigniter.com/userguide3/database/queries.html search "Handling Errors"







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 3 at 0:06

























            answered Oct 8 '16 at 17:28









            Omar MatijasOmar Matijas

            6116




            6116













            • Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

              – Ahmet Çavdar
              Oct 3 '17 at 4:01





















            • Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

              – Ahmet Çavdar
              Oct 3 '17 at 4:01



















            Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

            – Ahmet Çavdar
            Oct 3 '17 at 4:01







            Actually the documentation says; " the error() method will return an array containing its code and message". So, the way you get the code and message is $error['code'] $error['message']

            – Ahmet Çavdar
            Oct 3 '17 at 4:01




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33433725%2fcodeigniter-this-db-error-message-message-returns-null%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Angular Downloading a file using contenturl with Basic Authentication

            Monofisismo

            Olmecas