4

First of all sorry for my bad English..

I have this function in a model:

function insertUser($data){

$sql = "INSERT INTO USERS VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

$query = $this->db->query($sql, array(
    $data["uname"],
    $data["nome"],
    $data["dnuser"],
    $data["muser"],
    $data["fruser"],
    $data["cpuser"],
    $data["euser"],
    md5($data["passu"])
  ));

//return $this->db->_error_number();

} 

I have one primary key and when data is correct the function works but when is inserted a duplicate key the function doesn’t work. But how can i know that? i mean how can i catch the error ORA-00001 ??

BTW the commented line doesn’t work..

Thank you very much!!

3
  • Is the leasing _ needed in ->_error_number()? Commented Dec 8, 2012 at 23:33
  • yes, the function is defined that way in oci_driver.php in system folder... Commented Dec 9, 2012 at 0:43
  • What kind of class is $this->db then? Or what framework are you using? Which framework/application does this system folder belong to? Commented Dec 9, 2012 at 0:48

1 Answer 1

2

You can use try catch block...

function insertUser($data){

$sql = "INSERT INTO USERS VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

try{
$this->db->trans_start();
$query = $this->db->query($sql, array(
    $data["uname"],
    $data["nome"],
    $data["dnuser"],
    $data["muser"],
    $data["fruser"],
    $data["cpuser"],
    $data["euser"],
    md5($data["passu"])
  ));
$this->db->trans_commit();
}
catch(Exception $ex){
$this->db->trans_rollback();
echo "Error:".$ex;
}
} 

You can check the following article..

http://ellislab.com/codeigniter/user-guide/database/transactions.html

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

1 Comment

are you sure have tried those codes and get expected result? for me those codes didn't result anything.

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.