本文整理汇总了PHP中DBManager::getAffectedRowCount方法的典型用法代码示例。如果您正苦于以下问题:PHP DBManager::getAffectedRowCount方法的具体用法?PHP DBManager::getAffectedRowCount怎么用?PHP DBManager::getAffectedRowCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBManager
的用法示例。
在下文中一共展示了DBManager::getAffectedRowCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nextJob
/**
* Fetch the next job in the queue and mark it running
* @param string $clientID ID of the client requesting the job
* @return SugarJob
*/
public function nextJob($clientID)
{
$now = $this->db->now();
$queued = SchedulersJob::JOB_STATUS_QUEUED;
$try = $this->jobTries;
while ($try--) {
// TODO: tranaction start?
$id = $this->db->getOne("SELECT id FROM {$this->job_queue_table} WHERE execute_time <= {$now} AND status = '{$queued}' ORDER BY date_entered ASC");
if (empty($id)) {
return null;
}
$job = new SchedulersJob();
$job->retrieve($id);
if (empty($job->id)) {
return null;
}
$job->status = SchedulersJob::JOB_STATUS_RUNNING;
$job->client = $clientID;
$client = $this->db->quote($clientID);
// using direct query here to be able to fetch affected count
// if count is 0 this means somebody changed the job status and we have to try again
$res = $this->db->query("UPDATE {$this->job_queue_table} SET status='{$job->status}', date_modified={$now}, client='{$client}' WHERE id='{$job->id}' AND status='{$queued}'");
if ($this->db->getAffectedRowCount($res) == 0) {
// somebody stole our job, try again
continue;
} else {
// to update dates & possible hooks
$job->save();
break;
}
// TODO: commit/check?
}
return $job;
}
示例2: testGetAffectedRowCount
public function testGetAffectedRowCount()
{
if (!$this->_db->supports("affected_rows")) {
$this->markTestSkipped('Skipping, backend doesn\'t support affected rows');
}
$beanIds = $this->_createRecords(1);
$result = $this->_db->query("DELETE From contacts where id = '{$beanIds[0]}'");
$this->assertEquals(1, $this->_db->getAffectedRowCount($result));
}