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


PHP moodle_database::update_record_raw方法代码示例

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


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

示例1: handler_write

 /**
  * Write session handler.
  *
  * {@see http://php.net/manual/en/function.session-set-save-handler.php}
  *
  * NOTE: Do not write to output or throw any exceptions!
  *       Hopefully the next page is going to display nice error or it recovers...
  *
  * @param string $sid
  * @param string $session_data
  * @return bool success
  */
 public function handler_write($sid, $session_data)
 {
     global $USER;
     // TODO: MDL-20625 we need to rollback all active transactions and log error if any open needed
     if ($this->failed) {
         // do not write anything back - we failed to start the session properly
         return false;
     }
     $userid = 0;
     if (!empty($USER->realuser)) {
         $userid = $USER->realuser;
     } else {
         if (!empty($USER->id)) {
             $userid = $USER->id;
         }
     }
     if (isset($this->record->id)) {
         $data = base64_encode($session_data);
         // There might be some binary mess :-(
         // Skip db update if nothing changed,
         // do not update the timemodified each second.
         $hash = sha1($data);
         if ($this->lasthash === $hash and $this->record->userid == $userid and time() - $this->record->timemodified < 20 and $this->record->lastip == getremoteaddr()) {
             // No need to update anything!
             return true;
         }
         $this->record->sessdata = $data;
         $this->record->userid = $userid;
         $this->record->timemodified = time();
         $this->record->lastip = getremoteaddr();
         try {
             $this->database->update_record_raw('sessions', $this->record);
             $this->lasthash = $hash;
         } catch (dml_exception $ex) {
             if ($this->database->get_dbfamily() === 'mysql') {
                 try {
                     $this->database->set_field('sessions', 'state', 9, array('id' => $this->record->id));
                 } catch (Exception $ignored) {
                 }
                 error_log('Can not write database session - please verify max_allowed_packet is at least 4M!');
             } else {
                 error_log('Can not write database session');
             }
             return false;
         } catch (Exception $ex) {
             error_log('Can not write database session');
             return false;
         }
     } else {
         // fresh new session
         try {
             $record = new stdClass();
             $record->state = 0;
             $record->sid = $sid;
             $record->sessdata = base64_encode($session_data);
             // there might be some binary mess :-(
             $record->userid = $userid;
             $record->timecreated = $record->timemodified = time();
             $record->firstip = $record->lastip = getremoteaddr();
             $record->id = $this->database->insert_record_raw('sessions', $record);
             $this->record = $this->database->get_record('sessions', array('id' => $record->id));
             $this->lasthash = sha1($record->sessdata);
             $this->database->get_session_lock($this->record->id, SESSION_ACQUIRE_LOCK_TIMEOUT);
         } catch (Exception $ex) {
             // this should not happen
             error_log('Can not write new database session or acquire session lock');
             $this->failed = true;
             return false;
         }
     }
     return true;
 }
开发者ID:neogic,项目名称:moodle,代码行数:84,代码来源:sessionlib.php


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