1
雖然我正在尋找的Magento在SQL查詢日誌轉彎,我發現修改後,以如下Magento的核心query
功能:preg_replace_callback正則表達式的語法不正確
public function query($sql, $bind = array())
{
$this->_debugTimer();
try {
$sql = (string)$sql;
if (strpos($sql, ':') !== false || strpos($sql, '?') !== false) {
$this->_bindParams = $bind;
$sql = preg_replace_callback('#(([\'"])((2)|((.*?[^\])2)))#', array($this, 'proccessBindCallback'), $sql);
$bind = $this->_bindParams;
}
$code = 'SQL: ' . $sql . "rn";
if ($bind) {
$code .= 'BIND: ' . print_r($bind, true) . "rn";
}
$this->_debugWriteToFile("[".date('Y-m-d H:i:s')."] ".$code);
$result = parent::query($sql, $bind);
}
catch (Exception $e) {
$this->_debugStat(self::DEBUG_QUERY, $sql, $bind);
$this->_debugException($e);
}
$this->_debugStat(self::DEBUG_QUERY, $sql, $bind, $result);
return $result;
}
我不明白的是爲什麼preg_replace_callback
是否需要在這裏,當我將上面的代碼放到我的編輯器中時,在語法中包含preg_replace_callback
這一行的問題是什麼,它顯示了報價突出顯示?
有什麼建議嗎?
轉義單引號。看到這裏的顏色突出顯示? '''']'這個單引號關閉了你的PHP字符串封裝。 – chris85
你說得對,但是在這之後如果我運行我的代碼,它會在日誌中出現錯誤''''在同一行中出現' –
如果你有Magento的源代碼與你一起試用這個,把你的lib/Varien/Db/Adapter/Pdo/Mysql.php替換掉現有的'query'函數,然後運行Magento主頁,你會知道我得到了什麼錯誤。 –