Пример #1
0
 function &exec($sql, $skipModifiedMark = false, $db_lnk = null)
 {
     if (!$skipModifiedMark && preg_match('/(?:(delete\\s+from)|(insert\\s+into)|(update))\\s+([]0-9a-z_:"`.@[-]*)/is', $sql, $match)) {
         $table = strtoupper(trim(str_replace('`', '', str_replace('"', '', str_replace("'", '', $match[4])))));
         $now = time();
         $this->exec('UPDATE sdb_base_cache_expires SET expire = "' . $now . '" WHERE type = "DB" AND name = "' . strtoupper($table) . '"', true);
         if ($this->affect_row()) {
             cachemgr::set_modified('DB', $table, $now);
         }
     }
     if (!is_resource($db_lnk)) {
         if ($this->_rw_lnk) {
             $db_lnk =& $this->_rw_lnk;
         } else {
             $db_lnk =& $this->_rw_conn();
         }
     }
     if ($this->prefix != 'sdb_') {
         $sql = preg_replace('/([`\\s\\(,])(sdb_)([a-z\\_]+)([`\\s\\.]{0,1})/is', "\${1}" . $this->prefix . "\\3\\4", $sql);
     }
     if ($rs = mysql_query($sql, $db_lnk)) {
         self::$mysql_query_executions++;
         $db_result = array('rs' => &$rs, 'sql' => $sql);
         return $db_result;
     } else {
         trigger_error($sql . ':' . mysql_error($db_lnk), E_USER_WARNING);
         return false;
     }
 }
Пример #2
0
 /**
  * 数据库操作核心入口.
  *
  * @param $sql SQL语句
  * @param $skipModifiedMark 是否忽略缓存标记更新
  */
 public function exec($sql, $skipModifiedMark = false, $db_lnk = false, &$stmt = flase)
 {
     if ($this->prefix != 'vmc_') {
         $sql = preg_replace_callback('/([`\\s\\(,])(vmc_)([0-9a-z\\_]+)([`\\s\\.]{0,1})/is', array($this, 'fix_dbprefix'), $sql);
     }
     //删除、插入、更新 语句
     if (preg_match('/(?:(delete\\s+from)|(insert\\s+into)|(update))\\s+([]0-9a-z_:"`.@[-]*)/is', $sql, $match)) {
         //直接操作主库
         if (!$db_lnk) {
             $db_lnk = $this->_rw_lnk;
         }
         if (!$db_lnk) {
             $db_lnk = $this->_rw_lnk = $this->_rw_conn();
         }
         if (!$skipModifiedMark && cachemgr::enable()) {
             $table = strtoupper(trim(str_replace('`', '', str_replace('"', '', str_replace("'", '', $match[4])))));
             $now = time();
             $pos = strpos($table, strtoupper($this->prefix));
             if ($pos === 0) {
                 $table = substr($table, strlen($this->prefix));
             }
             $exec_count = $db_lnk->exec('UPDATE vmc_base_cache_expires SET expire = "' . $now . '" WHERE type = "DB" AND name = "' . $table . '"');
             if ($exec_count) {
                 //更新数据库表缓存标记
                 cachemgr::set_modified('DB', $table, $now);
             }
         }
         logger::debug('EXEC SQL:' . $sql);
         // debug 2015/8/31
         $this->last_query = $sql;
         $this->array_query[] = $sql;
         $affected = $db_lnk->exec($sql);
         if ($affected === false) {
             $this->error = $error_info = $db_lnk->errorInfo();
             $this->error_code = $db_lnk->errorCode();
             logger::error('MYSQL_ERROR! SQL:' . $sql);
             logger::error('ERROR_CODE:' . $db_lnk->errorCode() . 'ERROR_INFO:' . implode('::', (array) $error_info));
             return false;
         }
         return true;
     } else {
         //查询为主
         if ($this->_ro_lnk) {
             $db_lnk = $this->_ro_lnk;
         } else {
             $db_lnk = $this->_ro_conn();
         }
         logger::debug('QUERY SQL:' . $sql);
         $stmt = $db_lnk->query($sql);
         $db_res = array();
         while ($stmt && ($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
             $db_res[] = $row;
         }
         // debug 2015/8/31
         $this->last_query = $sql;
         $this->array_query[] = $sql;
         return array('rs' => $db_res, 'sql' => $sql);
     }
 }
Пример #3
0
 public function exec($sql, $skipModifiedMark = false, $db_lnk = null)
 {
     if ($this->prefix != 'sdb_') {
         //$sql = preg_replace('/([`\s\(,])(sdb_)([a-z\_]+)([`\s\.]{0,1})/is',"\${1}".$this->prefix."\\3\\4",$sql);
         $sql = preg_replace_callback('/([`\\s\\(,])(sdb_)([0-9a-z\\_]+)([`\\s\\.]{0,1})/is', array($this, 'fix_dbprefix'), $sql);
         //todo: 兼容有特殊符号的表名前缀
     }
     if (!$skipModifiedMark && cachemgr::enable() && preg_match('/(?:(delete\\s+from)|(insert\\s+into)|(update))\\s+([]0-9a-z_:"`.@[-]*)/is', $sql, $match)) {
         $table = strtoupper(trim(str_replace('`', '', str_replace('"', '', str_replace("'", '', $match[4])))));
         $now = time();
         $pos = strpos($table, strtoupper($this->prefix));
         if ($pos === 0) {
             $table = substr($table, strlen($this->prefix));
         }
         //todo: 真实表名
         $this->exec('UPDATE sdb_base_cache_expires SET expire = "' . $now . '" WHERE type = "DB" AND name = "' . $table . '"', true);
         if ($this->affect_row()) {
             cachemgr::set_modified('DB', $table, $now);
         }
     }
     if (!is_resource($db_lnk)) {
         if ($this->_rw_lnk) {
             $db_lnk = $this->_rw_lnk;
         } else {
             $db_lnk = $this->_rw_conn();
         }
     }
     if (defined("STRESS_TESTING")) {
         b2c_forStressTest::$sqlAmount++;
         b2c_forStressTest::slowSqlStart();
     }
     if ($rs = mysql_query($sql, $db_lnk)) {
         if (defined("STRESS_TESTING")) {
             b2c_forStressTest::slowSqlEnd($sql);
         }
         self::$mysql_query_executions++;
         logger::debug('sql:' . self::$mysql_query_executions . '.' . $sql);
         $db_result = array('rs' => $rs, 'sql' => $sql);
         return $db_result;
     } else {
         logger::error($sql . ':' . mysql_error($db_lnk));
         trigger_error($sql . ':' . mysql_error($db_lnk), E_USER_WARNING);
         return false;
     }
 }
Пример #4
0
 public function set_modified($key)
 {
     $vary_name = strtoupper(md5($this->app_id . $key));
     cachemgr::set_modified('CONF', $vary_name, syscache::instance('setting')->set_last_modify());
 }
Пример #5
0
 public function set_modified($key)
 {
     $vary_name = strtoupper(md5($this->app_id . $key));
     $now = time();
     $db = kernel::database();
     $db->exec('REPLACE INTO sdb_base_cache_expires (`type`, `name`, `expire`) VALUES ("CONF", "' . $vary_name . '",' . $now . ')', true);
     if ($db->affect_row()) {
         cachemgr::set_modified('CONF', $vary_name, $now);
     }
 }
Пример #6
0
Файл: app.php Проект: noikiy/snk
 public function set_modified($key)
 {
     $vary_name = strtoupper(md5($this->app_id . $key));
     $now = time();
     $db = vmc::database();
     $exec_count = $db->exec('REPLACE INTO vmc_base_cache_expires (`type`, `name`, `app`, `expire`) VALUES ("CONF", "' . $vary_name . '", "' . $this->app_id . '", ' . $now . ')', true);
     if ($exec_count) {
         cachemgr::set_modified('CONF', $vary_name, $now);
         syscache::instance('setting')->set_last_modify();
     }
 }