Welcome Guest, Not a member yet? Register   Sign In
REACTOR $this->db->set() not working in update

[eluser]Pedro Luz[/eluser]

Im having problems with the when doing updating. (REACTOR)

$this->db->where('id', $id);
$this->db->set('field', $data);

Even if i do


It updates all the records in the table. Sad

any ideas

The user guide says nothing about using "SET" when updating.
Don't know if it should work like that.

Just try this:
$data = array(
    'field' => $your_data

$this->db->where('id', $id);
$this->db->update('table', $data);

assuming $your_data (in your example '$data') is a variable and no array

EDIT: re reading the User Guide I see that you can use "SET" as well ..

If that code doesn't work please provide more of your code

[eluser]Pedro Luz[/eluser]
Quote:The user guide says nothing about using “SET” when updating.

It does. In the $this->db->update() documentation, the last line says...

Quote:You may also use the $this->db->set() function described above when performing updates.

I know it works by passing and array like u explained.

But it used to work with $this->db->set(), because i used to do that way. In 1.7.2

My code is just:

$id = 5;
$data = 'pimpampum';
$this->db->where('id', $id);
$this->db->set('field', $data);

I did set up a test db table and fired your code.
Only the row with the specified id was updated.

Are you sure your rows don't have the same id?
Otherwise I don't know what could be wrong.

Wouldn't it be beneficial if you were to first check the query to make sure its valid, without using CI's DB? Doesn't anyone use MYSQL Query Browsers, phpMyAdmin, or other interfaces to interact with their databases? If this were me, and I had this problem, I'd first try writing the query out to see if it works.

"UPDATE table SET field=$data WHERE id=$id";

If this still updates everything then it's your DB structure.

Theme © iAndrew 2016 - Forum software by © MyBB