$db->affected_rows always returning 0 after UPDATE query
Posted: Sat Jul 08, 2006 7:11 pm
I thought at first this could be because its not commiting. But i inserted
and tried
Anyway the problem is I'm executing this bit of code:
Which uses these:
And yet despite all this when i go back to see if the record has been updated, it has! This problem is not isolated to this query.
This problem has only started happening recently, so I've obviously changed something to muck it up but i've no idea.
Code: Select all
$this->db->query('COMMIT');Code: Select all
$this->db->autocommit(true);Code: Select all
public function publishAction()
{
$id = (int)$this->_getParam('id');
if (!$id) {
$this->illusiveResource();
}
$db = Zend::registry('db');
if($affected = $db->unpublishSite($id)) {
$this->_redirect('/' . $this->controllerName . '/list/');
} else {
// this but always executes
var_dump($affected); // and this is always int(0)
$this->illusiveResource();
}
return true;
}Code: Select all
/**
* Unpublishes a site. Returns whether the site was updated or not.
*
* @param int $siteId
* @return bool
*/
public function _unpublishSite($arg)
{
$q = 'UPDATE Site SET isOnline = 0, wentOffline = NOW() WHERE siteId = '.$arg[0];
$result = $this->qq($q, __FUNCTION__);
return $this->db->affected_rows;
}
/**
* Execute a query and throw an exception if it fails.
*
* @param string $q
* @param string $name the name of the function calling qq(); use __FUNCTION__
* @return mysqli_result
*/
private function qq($q,$name)
{
$status = $this->db->query($q);
$this->queriesExecuted++;
if(!$status) {
$name.= ' generated the following error: '.$this->db->error;
throw new QueryException($name,$this->db->errno,$q);
}
else return $status;
}This problem has only started happening recently, so I've obviously changed something to muck it up but i've no idea.