本文整理匯總了PHP中moodle_database::record_exists方法的典型用法代碼示例。如果您正苦於以下問題:PHP moodle_database::record_exists方法的具體用法?PHP moodle_database::record_exists怎麽用?PHP moodle_database::record_exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類moodle_database
的用法示例。
在下文中一共展示了moodle_database::record_exists方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: session_exists
/**
* Check for existing session with id $sid.
*
* Note: this verifies the storage backend only, not the actual session records.
*
* @param string $sid
* @return bool true if session found.
*/
public function session_exists($sid)
{
try {
return $this->database->record_exists('sessions', array('sid' => $sid, 'state' => 0));
} catch (\dml_exception $ex) {
return false;
}
}
示例2: get_lock
/**
* Create and get a lock
* @param string $resource - The identifier for the lock. Should use frankenstyle prefix.
* @param int $timeout - The number of seconds to wait for a lock before giving up.
* @param int $maxlifetime - Unused by this lock type.
* @return boolean - true if a lock was obtained.
*/
public function get_lock($resource, $timeout, $maxlifetime = 86400)
{
$token = $this->generate_unique_token();
$now = time();
$giveuptime = $now + $timeout;
$expires = $now + $maxlifetime;
if (!$this->db->record_exists('lock_db', array('resourcekey' => $resource))) {
$record = new \stdClass();
$record->resourcekey = $resource;
$result = $this->db->insert_record('lock_db', $record);
}
$params = array('expires' => $expires, 'token' => $token, 'resourcekey' => $resource, 'now' => $now);
$sql = 'UPDATE {lock_db}
SET
expires = :expires,
owner = :token
WHERE
resourcekey = :resourcekey AND
(owner IS NULL OR expires < :now)';
do {
$now = time();
$params['now'] = $now;
$this->db->execute($sql, $params);
$countparams = array('owner' => $token, 'resourcekey' => $resource);
$result = $this->db->count_records('lock_db', $countparams);
$locked = $result === 1;
if (!$locked) {
usleep(rand(10000, 250000));
// Sleep between 10 and 250 milliseconds.
}
// Try until the giveup time.
} while (!$locked && $now < $giveuptime);
if ($locked) {
$this->openlocks[$token] = 1;
return new lock($token, $this);
}
return false;
}