本文整理汇总了PHP中rcube_db::set_option方法的典型用法代码示例。如果您正苦于以下问题:PHP rcube_db::set_option方法的具体用法?PHP rcube_db::set_option怎么用?PHP rcube_db::set_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rcube_db
的用法示例。
在下文中一共展示了rcube_db::set_option方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write_record
/**
* Writes single cache record into DB.
*
* @param string $key Cache key name
* @param mixed $data Serialized cache data
*
* @param boolean True on success, False on failure
*/
private function write_record($key, $data)
{
if (!$this->db) {
return false;
}
// don't attempt to write too big data sets
if (strlen($data) > $this->max_packet_size()) {
trigger_error("rcube_cache: max_packet_size ({$this->max_packet}) exceeded for key {$key}. Tried to write " . strlen($data) . " bytes", E_USER_WARNING);
return false;
}
if ($this->type == 'memcache' || $this->type == 'apc') {
$result = $this->add_record($this->ckey($key), $data);
// make sure index will be updated
if ($result) {
if (!array_key_exists($key, $this->cache_sums)) {
$this->cache_sums[$key] = true;
}
$this->load_index();
if (!$this->index_changed && !in_array($key, $this->index)) {
$this->index_changed = true;
}
}
return $result;
}
$db_key = $this->prefix . '.' . $key;
// Remove NULL rows (here we don't need to check if the record exist)
if ($data == 'N;') {
$result = $this->db->query("DELETE FROM {$this->table} WHERE `cache_key` = ?", $db_key);
return !$this->db->is_error($result);
}
$key_exists = array_key_exists($key, $this->cache_sums);
$expires = $this->ttl ? $this->db->now($this->ttl) : 'NULL';
if (!$key_exists) {
// Try INSERT temporarily ignoring "duplicate key" errors
$this->db->set_option('ignore_key_errors', true);
$result = $this->db->query("INSERT INTO {$this->table} (`expires`, `cache_key`, `data`)" . " VALUES ({$expires}, ?, ?)", $db_key, $data);
$this->db->set_option('ignore_key_errors', false);
}
// otherwise try UPDATE
if (!isset($result) || !($count = $this->db->affected_rows($result))) {
$result = $this->db->query("UPDATE {$this->table} SET `expires` = {$expires}, `data` = ?" . " WHERE `cache_key` = ?", $data, $db_key);
$count = $this->db->affected_rows($result);
}
return $count > 0;
}
示例2: add_thread_row
/**
* Saves thread data into database
*/
private function add_thread_row($mailbox, $data, $mbox_data = array(), $exists = false)
{
$data = array($this->db->encode($data, true), (int) $this->skip_deleted, (int) $mbox_data['UIDVALIDITY'], (int) $mbox_data['UIDNEXT']);
$data = implode('@', $data);
$expires = $this->ttl ? $this->db->now($this->ttl) : 'NULL';
if ($exists) {
$res = $this->db->query("UPDATE {$this->thread_table}" . " SET `data` = ?, `expires` = {$expires}" . " WHERE `user_id` = ?" . " AND `mailbox` = ?", $data, $this->userid, $mailbox);
if ($this->db->affected_rows($res)) {
return;
}
}
$this->db->set_option('ignore_key_errors', true);
$res = $this->db->query("INSERT INTO {$this->thread_table}" . " (`user_id`, `mailbox`, `expires`, `data`)" . " VALUES (?, ?, {$expires}, ?)", $this->userid, $mailbox, $data);
// race-condition, insert failed so try update (#1489146)
// thanks to ignore_key_errors "duplicate row" errors will be ignored
if (!$exists && !$res && !$this->db->is_error($res)) {
$this->db->query("UPDATE {$this->thread_table}" . " SET `expires` = {$expires}, `data` = ?" . " WHERE `user_id` = ?" . " AND `mailbox` = ?", $data, $this->userid, $mailbox);
}
$this->db->set_option('ignore_key_errors', false);
}
示例3: init_db
/**
* Initialize the database with the according schema
*
* @param rcube_db $db Database connection
*
* @return boolen True on success, False on error
*/
public function init_db($db)
{
$engine = $db->db_provider;
// read schema file from /SQL/*
$fname = INSTALL_PATH . "SQL/{$engine}.initial.sql";
if ($sql = @file_get_contents($fname)) {
$db->set_option('table_prefix', $this->config['db_prefix']);
$db->exec_script($sql);
} else {
$this->fail('DB Schema', "Cannot read the schema file: {$fname}");
return false;
}
if ($err = $this->get_error()) {
$this->fail('DB Schema', "Error creating database schema: {$err}");
return false;
}
return true;
}