CodeIgniter Forums

Full Version: Duplicate record in postgresql from CodeIgniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Everyone,

 Before I have used mysql, for insert action my code : 

// in mymodel
 public function insertData($table, $data) {
        $res=$this->db->insert($table, $data);
        return  $db_error = $this->db->error();
         
    }
// in my controller 
 $result = $this->mymodel->insertData($mytable, $data);


if ($result['code'] == 1062){
echo "dublicate"
}

However now I am using postgresql and it returns error like this:

A PHP Error was encountered
Severity: Warning
Message: pg_query(): Query failed: ERROR: duplicate key value violates unique constraint "user_keywords_keyword_key" DETAIL: Key (keyword)=(fa) already exists.
Filename: postgre/postgre_driver.php
Line Number: 242

array(2) { ["code"]=> string(0) "" ["message"]=> string(126) "ERROR: duplicate key value violates unique constraint "user_keywords_keyword_key" DETAIL: Key (keyword)=(fa) already exists." } 


my question is that how to ignore this error
I don't have an answer to your question, but will remind you of the forum guidelines you agreed to at signup, namely that new users have their first few posts moderated. That is why your second, third & fourth post have not shown up yet either, and they will be deleted.

See the link at the top of each subforum ... https://forum.codeigniter.com/misc.php?a...les&fid=24
Did you set your Primary key to Auto Increment?
(03-25-2019, 03:25 AM)neuron Wrote: [ -> ]Did you set your Primary key to Auto Increment?

Keyword column is unique when user insert a keyword if it is already exist then I get the exeption
(03-25-2019, 04:32 AM)fatihdilmac Wrote: [ -> ]
(03-25-2019, 03:25 AM)neuron Wrote: [ -> ]Did you set your Primary key to Auto Increment?

Keyword column is unique when user insert a keyword if it is already exist then I get the exeption

Yes I have set my primary key auto increment