2011-02-07 28 views
0

在PHP腳本中,我需要更新標題,內容字段。 如果我將「@」放入內容中,則會收到錯誤「說明:'@'附近的語法錯誤。」 我固定的符號「」 是否有逃逸或框架DB層的任何解決方案如何在SQL查詢中轉義符號?

我被迫使用f **納克MS SQL :(

代碼:?

$conn = new COM ("ADODB.Connection") 
$db_conn = $conn->open('bla-bla-password...'); 
$query = sprintf("UPDATE page SET title='%s', page_content='%s' WHERE id=%d;", addslashes($title), addslashes($content), intval($id)); 
$rs = $db_conn->execute($query); 
+1

http://stackoverflow.com/questions/574805/how-to-escape-strings-in-mssql-using-php 從快得到這個使用谷歌搜索 – kirilloid 2011-02-07 17:28:24

回答

4

使用PDO prepared statements逃避特殊字符...不是的sprintf或使用addslashes。

+1

或者至少避免像鼠疫這樣的`addslashes()`,並使用你的數據庫的本地引用函數 – 2011-02-07 17:48:23