Welcome Guest, Not a member yet? Register   Sign In
update & like - problem
#1

[eluser]Lazos[/eluser]
Hi I have this query but is not working correct (maybe a bug?). When I use the same query for SELECTing the rows that LIKE 'TinyMCE_set_' I am getting the result 12 on my database which is the correct one but when I use the same query to update is changing ALL my fields to 0.
I am doing something wrong?

Code:
function updateTinyMCESet() {
        $data = array(
            'sitepref_value'    => 0
        );
        $this->db->like('sitepref_name', 'TinyMCE_set_', 'both');
        $this->db->update('my_siteprefs', $data);
    }
#2

[eluser]xwero[/eluser]
You can check if the query that is generated is the one you want if you add
Code:
echo $this->db->last_query();
after the update method.
#3

[eluser]Lazos[/eluser]
You are right mate the result I am getting is "UPDATE `my_siteprefs` SET `sitepref_value` = 0".

Why is that? How I can use the LIKE now?
#4

[eluser]xwero[/eluser]
it seems the AR library still has a problem seeing the like parts independent form the where part of the query in the update method. A quick fix is using the where method but then you have to write the like part in full.
If you want to change the AR library you have to replace following line in the update method
Code:
$sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
with
Code:
$sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, array_merge($this->ar_where,$this->ar_like), $this->ar_orderby, $this->ar_limit);
That should do the trick.
#5

[eluser]Lazos[/eluser]
For now I use this $query = $this->db->query('UPDATE my_siteprefs SET sitepref_value = 0 WHERE sitepref_name LIKE "%TinyMCE_set_%"'); which did the trick but later I will change the line in AR library so all the queries will be the same Big Grin.




Theme © iAndrew 2016 - Forum software by © MyBB