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


PHP Database::fetchField方法代码示例

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


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

示例1: exit

if (!$forked) {
    exit(1);
}
// Avoid forking connection crash, renew the connection.
Database::disconnect();
// Get maximum allowed connections before table lock.
$capLimit = (int) @conf::get('system::crontab.process_limit');
if (!$capLimit) {
    $capLimit = Process::MAXIMUM_CAPACITY;
}
// Start transaction before lock tables.
Database::beginTransaction();
// Pick next awaiting process
Database::locKTables([FRAMEWORK_COLLECTION_PROCESS . ' READ']);
$res = (int) Database::fetchField('SELECT IFNULL(SUM(`capacity`), 0) as occupation
    FROM `' . FRAMEWORK_COLLECTION_PROCESS . '`
    WHERE `pid` IS NOT NULL AND `pid` > 0');
Database::unlockTables(true);
if ($res >= $capLimit) {
    Log::debug('Active processes has occupied maximum server capacity, daemon exits.');
    Database::rollback();
    die;
}
unset($res, $capLimit);
Database::lockTables(array(FRAMEWORK_COLLECTION_PROCESS . ' LOW_PRIORITY WRITE', FRAMEWORK_COLLECTION_PROCESS . ' as `active` LOW_PRIORITY WRITE', FRAMEWORK_COLLECTION_PROCESS . ' as `inactive` LOW_PRIORITY WRITE'));
$process = Database::fetchRow('SELECT `inactive`.* FROM `' . FRAMEWORK_COLLECTION_PROCESS . '` as `inactive`
    LEFT JOIN ( SELECT `type`, SUM(`capacity`) as `occupation` FROM `' . FRAMEWORK_COLLECTION_PROCESS . '`
        WHERE `pid` IS NOT NULL GROUP BY `type` ) as `active`
      ON `active`.`type` = `inactive`.`type`
    WHERE `timestamp` <= CURRENT_TIMESTAMP
      AND `start_time` <= CURRENT_TIMESTAMP
开发者ID:Victopia,项目名称:prefw,代码行数:31,代码来源:Process.php

示例2: beforeSave

 /**
  * @protected
  *
  * A TaskInstance can only be saved when,
  *   1. WorkInstance is mutable, or
  *   2. WorkInstance exists and this is creating, or
  *   3. WorkInstance is Open, and nextTask is empty or equals to this one.
  */
 function beforeSave(array &$errors = array())
 {
     $workInstance = $this->workInstance();
     if ($workInstance->immutable()) {
         throw new FrameworkException('Task instance cannot be modified.');
     }
     if (!$workInstance || $workInstance->state == $workInstance::STATE_CLOSE) {
         throw new FrameworkException('Work instance does not exist.');
     }
     if ($this->isCreate()) {
         // note; loop until we find a unique uuid
         do {
             $this->identity(Database::fetchField("SELECT UNHEX(REPLACE(UUID(), '-', ''))"));
         } while ($this->find(array($this->primaryKey() => $this->identity())));
     } else {
         if ($workInstance->nextTask != $this->identity()) {
             throw new FrameworkException('Task is not active.');
         }
     }
     return parent::beforeSave($errors);
 }
开发者ID:Victopia,项目名称:prefw,代码行数:29,代码来源:TaskInstance.php

示例3: beforeSave

 /**
  * @protected
  *
  * Takes care of tasks and settings.
  */
 function beforeSave(array &$errors = array())
 {
     // packUuid
     if ($this->isCreate()) {
         // note; loop until we find a unique uuid
         do {
             $this->identity(Database::fetchField("SELECT UNHEX(REPLACE(UUID(), '-', ''))"));
         } while ($this->find(array($this->primaryKey() => $this->identity())));
     } else {
         if (isset($this->uuid)) {
             $this->uuid = util::packUuid($this->uuid);
         }
     }
     parent::beforeSave($errors);
     if (!$errors) {
         if (empty($this->tasks)) {
             unset($this->tasks);
         } else {
             // Only take task identity and settings
             $this->tasks = array_reduce($this->tasks, function ($result, $task) {
                 $taskModel = new Task($task);
                 $taskModel->load($taskModel->identity());
                 if ($taskModel->identity()) {
                     $result[] = array_filter(array('name' => $taskModel->name, 'version' => $taskModel->version, 'settings' => @$task['settings']));
                 }
                 return $result;
             }, array());
             \core\Log::info('Tasks', $this->tasks);
         }
     }
     return $this;
 }
开发者ID:Victopia,项目名称:prefw,代码行数:37,代码来源:Work.php

示例4: generateToken

 /**
  * Generate a one-time authentication token string for additional
  * security for AJAX service calls.
  *
  * Each additional call to this function overwrites the token generated last time.
  *
  * @return One-time token string, or null on invalid session.
  */
 static function generateToken($sid = null)
 {
     $res = static::ensure($sid);
     if ($res !== true) {
         return $res;
     }
     $res =& static::$currentSession;
     $res['token'] = Database::fetchField("SELECT UNHEX(REPLACE(UUID(),'-',''));");
     unset($res['timestamp']);
     if (Node::set($res) === false) {
         return null;
     }
     return util::unpackUuid($res['token']);
 }
开发者ID:Victopia,项目名称:prefw,代码行数:22,代码来源:Session.php

示例5: beforeSave

 /**
  * Process POST data with current step.
  */
 function beforeSave(array &$errors = array())
 {
     // note; WorkInstance is locked from modification, except when staging and processing.
     if (!$this->isCreate() && $this->_immutable) {
         // todo; Validation messages is not yet put into play.
         $errors[] = 'Cannot modify work instance.';
         throw new FrameworkException('Cannot modify work instance.');
     }
     if ($this->state == static::STATE_CLOSE) {
         $this->nextTask = null;
     }
     // binary encode task uuid
     if (!empty($this->nextTask)) {
         $this->nextTask = util::packUuid($this->nextTask);
     }
     if (isset($this->uuid)) {
         $this->uuid = util::packUuid($this->uuid);
     }
     // reset empty data store
     if (empty($this->dataStore)) {
         unset($this->dataStore);
     }
     // note; task instances will not be created after work instance creation.
     if ($this->isCreate()) {
         // note; loop until we find a unique uuid
         do {
             $this->identity(Database::fetchField("SELECT UNHEX(REPLACE(UUID(), '-', ''))"));
         } while ($this->find(array($this->primaryKey() => $this->identity())));
         // note; Only users with permission to first task can create.
         // note;security; Copy tasks from parent work again.
         if (empty($this->state)) {
             $this->state = static::STATE_OPEN;
         }
         $this->__tasks = array_reduce($this->work()->tasks, function ($result, $task) {
             $task = new TaskInstance($task);
             $task->workInstance($this);
             $task->order = count($result);
             $result[] = $task;
             return $result;
         }, array());
         $task = reset($this->__tasks);
         if (!$task) {
             throw new FrameworkException('Unable to load work tasks.');
         }
         if (!$this->__isInternal && !array_intersect((array) @$this->__request->user->groups, $task->userGroups())) {
             throw new FrameworkException('User has no permission to work on this.');
         }
     }
     unset($this->tasks);
     return parent::beforeSave($errors);
 }
开发者ID:Victopia,项目名称:prefw,代码行数:54,代码来源:WorkInstance.php


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