Where Clause Not Working

Issue #1 wontfix
Former user created an issue

I can't figure out what I'm doing wrong.

I use this

$result = $this->db->update( 'addresses', $data['address'] )->where('id', 61 )->execute();

And it updates every record in the table, not just the one with id 61.

Here is the result dump

Database: Object _delete: false _executed: true _fromTable: null _last_query: "UPDATE addresses SET address1 = '1 Main St', address2 = '', city = 'Miami', state = 'IL', postal = '33333', country = 'US', phone = '305551212, record_id = '59'" _limit: null _mysqli:mysqli: Object _offset: null _result: true affected_rows: 37 array_groupby: Array[0] array_having: Array[0] array_like: Array[0] array_orderby: Array[0] array_select: Array[0] array_where: Array[0] array_wherein: Array[0] debug: true die_on_error: true error: "" table_prefix: null

Comments (2)

  1. Vivek N repo owner

    Hi

    Try where() before update() as

    $result = $this->db->where('id', 61 )->update( 'addresses', $data['address'] )->execute();

    Placing where() after update() doesn't work for me as well. I'll fix this out. I always use where() first. No wonder why I didn't notice

  2. Vivek N repo owner

    I believe, calling where() before update() is effective therefore I'll leave that here. I've updated the wiki to reflect this. I've also added a new method dryrun() which will allow you to see the query before you execute it.

  3. Log in to comment