8

What I want to do is something like this:

function registerUser($username, $password){

$this->db->insert('tblUsers', array('username'=>$username, 'password'=>md5($password)));
if($this->db->_error_number()==1062){
    return "DUPLICATE";
}
return true;

}

However, at the moment if there is a duplicate key then its not letting me get to the _error_number() bit. Its displaying an error like this:

enter image description here

How do I stop codeigniter from bailing with an error and passing the error number to me to deal with appropriately?

Thanks

2 Answers 2

12

You can access MySQL error messages in Codeigniter using:

$this->db->_error_message();

Apparently DB_DEBUG needs to be set to false in the database config file:

Ensure DB_DEBUG is set to FALSE in the database config file, or execution will halt when a mysql error occurs (it does not get thrown, it justs exits from the php interpreter)

Link: http://codeigniter.com/forums/viewthread/79950/#413830

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I know that, I'm using _error_number() to get the error number in the code above. However, its not geting to there, its ditching before hand, and printing an error.
See my revised solution. Note that you will no longer be able to see the MySQL error messages without using _error_message()/_error_number()
8

Suggestion:

$orig_db_debug = $this->db->db_debug;

$this->db->db_debug = FALSE;

RUN QUERY HERE

$this->db->db_debug = $orig_db_debug;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.