当前位置: 首页>>代码示例>>PHP>>正文


PHP moodle_database::count_records方法代码示例

本文整理汇总了PHP中moodle_database::count_records方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_database::count_records方法的具体用法?PHP moodle_database::count_records怎么用?PHP moodle_database::count_records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在moodle_database的用法示例。


在下文中一共展示了moodle_database::count_records方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:45,代码来源:db_record_lock_factory.php

示例2: entries_count

 /**
  * @param moodle_database $db the database connection to use to access the cache.
  * @return int the number of entries in the cache.
  */
 public static function entries_count($db)
 {
     return $db->count_records('qtype_stack_cas_cache');
 }
开发者ID:profcab,项目名称:moodle-qtype_stack,代码行数:8,代码来源:connector.dbcache.class.php


注:本文中的moodle_database::count_records方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。