我正在研究一個PHP代碼,它將從XML中讀取數據,將它存儲在MySQL中。到目前爲止,我已經指出了從XML文件中讀取數據並在網站上回應它的地方。這裏是代碼:PHP - XML到MySQL
<?php
//mysql connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("bet_sql") or die(mysql_error());
$xml = simplexml_load_file('http://cachepricefeeds.williamhill.com/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=46&marketSort=MR&filterBIR=N');
foreach ($xml->response->williamhill->class->type as $type) {
$type_attrib = $type->attributes();
$type_attrib['id'];
$type_attrib['name'];
foreach ($type->market as $event) {
$event_attrib = $event->attributes();
$event_attrib['id'];
$event_attrib['name'];
$event_attrib['date'];
$event_attrib['url'];
foreach ($event->participant as $participant) {
$participant_attrib = $participant->attributes();
$participant_attrib['name'];
$participant_attrib['oddsDecimal'];
}
}
mysql_query("INSERT INTO games (type_id, type_name, event_id, event_name, event_url, participant_name, participant_odds)
VALUES ($type_attrib[id], $type_attrib[name], $event_attrib[id], $event_attrib[name], $event_attrib[url], $participant_attrib[name], $participant_attrib[oddsDecimal]) ")
or die(mysql_error());
}
?>
我在做什麼錯誤的mysql_query?我正在處理此消息:
您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的正確語法手冊「甲級聯賽,134465843,ZULTE-Waregem的v亨克 - 75分鐘投注,」在第2行
感謝您的幫助!
謹慎的只是一個字,因爲我看到你的體育書數據搞亂。如果你遇到這種類型的錯誤,你必須是MySQL的新手,如果沒有人監督這個過程,可能不應該在生產環境中處理這些數據。 – Jasper
您沒有在查詢中引用數據,您應該使用PDO或MySQLi,它們允許您準備語句。 – Jon