Welcome Guest, Not a member yet? Register   Sign In
It's not return false, If update failed
#1

[eluser]luffy[/eluser]
Hi, everyone

I use the method
return $this->db->update(table, $data);

it returns 1

But the sql is wrong. it still return 1?

How to return false?
#2

[eluser]├╝berfuzz[/eluser]
Maybe you could tell it to return true if things are dandy... else false.
Code:
$update = $this->db->update(table, $data);

if($update)
{
    return TRUE;
}
else
{
    return FASLSE;
}
#3

[eluser]luffy[/eluser]
The $update value is always 1, so it always true.
#4

[eluser]Mareshal[/eluser]
UPDATE returns 0 when query has an error or something, can't connect to database

I would try this

Code:
$this->db->update(table, $data);
$update = $this->db->affected_rows();

if($update == 1)
{
    return TRUE;
}
else
{
    return FALSE;
}

and after you should try

Code:
$this->db->last_query();

good luck
#5

[eluser]luffy[/eluser]
Nice, It's ok now.... Thanks

When insert, delete, update, I have to use the method
$result = $this->db->affected_rows();
#6

[eluser]Phil Sturgeon[/eluser]
Remember that affected_rows() will be 0 if nothing happened, so it cant be used to say "oh no there was an error with the query" as technically it would be fine.
#7

[eluser]luffy[/eluser]
Ha, Nice Smile




Theme © iAndrew 2016 - Forum software by © MyBB