Welcome Guest, Not a member yet? Register   Sign In
$this->db->affected_rows() always returning 0
#1

[eluser]Armchair Samurai[/eluser]
I'm not sure exactly if this is a CI problem, a MySQL problem or something completely different, but the affected_rows() function doesn't seem to be working properly for this query.

In one of the models, I have this function:
Code:
function edit($arr)
{
    $sql = "INSERT INTO table (id_1, id_2, foo, bar, created)
            VALUES (?, ?, ?, ?, ?)
            ON DUPLICATE KEY
            UPDATE foo = VALUES(foo), bar = VALUES(bar), modified = VALUES(created)";
    $this->db->query($sql, $arr);
    return $this->db->affected_rows() > 0 ? TRUE : FALSE;
}
The query itself works perfectly, but when I call affected_rows(), it is always returning 0. For the moment I have rewritten the function to run two queries as a stop gap measure (in which case affect_rows() works nicely), but I'm curious as to why the original query is causing issues. Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB