Welcome Guest, Not a member yet? Register   Sign In
returning result of an UPDATE query
#1

[eluser]stef25[/eluser]
In my models I always return $this->db->affected_rows() to make sure something was inserted, update or deleted.

Problem is that in my small custom CMS, a blog article is opened for editing and the user submits the form without making any modifications (pointless but can still be done), this RETURN gives FALSE, the same response as if there was an error. And I can

Is there a way to RETURN a value from a query that shows a TRUE response if no changes were made but there was no error?
#2

[eluser]mddd[/eluser]
Isn't it so that $this->db->update() return true or false, indicating an error or not??
Code:
$this->db->set('column', 'value');
$result = $this->db->update('table');
if (!$result)
{
   // there was an error
}
else if (!$this->db->affected_rows())
{
   // no error, but nothing changed
}
else
{
   // record changed
}
#3

[eluser]stef25[/eluser]
Works, thanks!




Theme © iAndrew 2016 - Forum software by © MyBB