1

I'm trying to find something along the lines of insert_or_update (similar to what Laravel offers) in CodeIgniter 3. The closest I have found is $this->db->replace(), but I can't find anything that specifies that it can/can't be used alongside a ->where(). Based on the docs I don't believe this will work since it doesn't list ->where() as an option, but I wanted to double check this as well.

I'm hoping I can do something like...

$data = [...];
$whereSearch = [...];
$this->db->replace($data)->where($whereSearch);
0

2 Answers 2

1

The key here to quote the documentation is

using PRIMARY and UNIQUE keys as the determining factor.

Replace only works based on your keys to replace the values in a table. You might find Does replace into have a where clause? helpful as well.

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

Comments

0
$this->db->where('column_name',$compared_data); 
$this->db->set('column_name',$updated_data);
$this->db->update('table_name');

Would this be what you're looking for?

1 Comment

I don't believe so. I was wanting a single function call that would determine if an insert or an update should be performed. The replace() function seemed like an option that might work, but the data that I'm needing this for doesn't have the required keys in this instance.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.