我正在爲一個學校項目製作基於Faroo.com的API(http://www.faroo.com/hp/api/api.html)的搜索引擎。我想索引Faroo的索引,以便用戶(在我的情況下,孩子們)可以投票或單獨投票結果。MySQL「INSERT INTO」 - 錯誤:我必須使用哪種引用?
什麼我(PHP)-script是這樣的:
Look in the MySQL-database if the query exists.
yes => load the results from the database and show them to the user
no => load the results from Faroo, show those results to the user and store them in the database
我的數據庫看起來是這樣的:
我得到存儲在列從Faroo的所有數據API,'id'列除外。
(的存儲在數據庫中的Faroo數據)的最後一部分是哪裏出了問題:
for($x=0; $x<$tel; $x++){
$sql = "INSERT INTO queries (`id`, `query`, `title`, `url`, `domain`, `kwic`, `votes`) VALUES (NULL, $q, $titles[$x], $urls[$x], $domains[$x], $kwics[$x], 0);";
echo '<br />'.$x.'e query: @'.$sql.'@';
if(!$resultaat = $db->query($sql)){
die('De query kon niet worden uitgevoerd: [' . $db->error . ']');
}
$resultaat = mysqli_fetch_array($resultaat);
}
$tel
是計數我從Faroo得到的結果數的變量。它在這段代碼之前被定義。 當我運行這段代碼,我得到一個不錯的MySQL錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'States Bureau of Mines - Wikipedia, the free encyclopedia, www.wikipedia.org' at line 1
我已經搜查,搜查,但我找不到SQL錯誤是什麼。我認爲這與字符串中的奇怪字符有關,或者我的引用是錯誤的?
親切的問候, 最大
您需要引用您的字符串值;或者甚至更好地使用[參數化查詢](http://stackoverflow.com/questions/728229/parameters-in-mysqli)。 –