/** * 写入指定 id 的 session 数据 * * @param string $sessid * @param string $data * * @return boolean */ function sessionWrite($sessid, $data) { $sessid = $this->dbo->qstr($sessid); $sql = "SELECT COUNT(*) FROM {$this->tableName} WHERE {$this->fieldId} = {$sessid}"; $data = $this->dbo->qstr($data); $activity = time(); $fields = (array) $this->_beforeWrite($sessid); if ((int) $this->dbo->getOne($sql) > 0) { $sql = "UPDATE {$this->tableName} SET {$this->fieldData} = {$data}, {$this->fieldActivity} = {$activity}"; if (!empty($fields)) { $arr = array(); foreach ($fields as $field => $value) { $arr[] = $this->dbo->qfield($field) . ' = ' . $this->dbo->qstr($value); } $sql .= ', ' . implode(', ', $arr); } $sql .= " WHERE {$this->fieldId} = {$sessid}"; } else { $extraFields = ''; $extraValues = ''; if (!empty($fields)) { foreach ($fields as $field => $value) { $extraFields .= ', ' . $this->dbo->qfield($field); $extraValues .= ', ' . $this->dbo->qstr($value); } } $sql = "INSERT INTO {$this->tableName} ({$this->fieldId}, {$this->fieldData}, {$this->fieldActivity}{$extraFields}) VALUES ({$sessid}, {$data}, {$activity}{$extraValues})"; } __TRY(); $this->dbo->execute($sql); $ex = __CATCH(); return !__IS_EXCEPTION($ex); }
/** * 获得一个字段名的完全限定名 * * @param string $fieldName * @param string $tableName * * @return string */ function qfield($fieldName, $tableName = null) { if (is_null($tableName)) { $tableName = $this->fullTableName; } return $this->dbo->qfield($fieldName, $tableName, $this->schema); }