• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Duplicate record in postgresql from CodeIgniter

#1
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
Reply

#2
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
Reply

#3
Did you set your Primary key to Auto Increment?
Reply

#4
(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
Reply

#5
(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
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.