Beispiel #1
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;
     }
 }