我對PHP和mysqli很陌生,並且正試圖爲我玩的遊戲放置一個統計站點。在一個堅果殼中,這個代碼1)通過用戶(通過URL)查找最後的X架次(這裏是1,但可以改變爲任意數量),2)Curl的結果,3)將它放入/tmp/sorties.csv,然後4)將數據本地infle /tmp/sortie.csv加載到我的數據庫。在加載數據本地infile寫入數據庫時遇到問題
它確實連接到數據庫(會員表),並通過成員/玩家名稱(回溯爲「正在更新」)查詢以及遊戲信息(每個玩家在遊戲中有數據數據庫) - 我已將頭部註釋掉,以便查看回傳的內容。
我的網站託管購買第三方,但使用SQL 5.5.32,PHP 5.3.13,是一個Linux/Debian平臺。任何(和所有)援助非常感謝,我實際上通過使用這裏提供的一些問題和答案寫了絕大多數的援助。我確實有這個代碼的唯一MySQL版本,它有相同的錯誤(2天前開始工作不正常),並且希望更新到mysqli可以解決問題。數據庫字段在數量和數據類型上都匹配。
//header("Location: /hcman/delsorties.php"); //After sorties put into database - clears any that are not valid
include 'Data/openi.php';
//Collect player name info
$query = "SELECT name FROM Members";
$result=$link->query($query);
// Array
$rows = array();
while($row = $result->fetch_array())
{
$rows[] =$row['name'];
}
// collect sortie data
foreach ($rows as $player)
{
$url = "http://csr.wwiionline.com//player_sorties_csv.php?username=".$player."&startsortie=0&sortiecount=1";
$path = '/tmp/sortie.csv' ;
// echo Player name -- works
echo "<br /><br />Updating for ".$player."<br />" ;
//Curl to tmp file (aka $path)
$ch = curl_init($url);
if($ch === false)
{
die('Failed to create curl handle');
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($ch);
if(!curl_exec($ch))
{
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
curl_close($ch);
file_put_contents($path,$result);
//show sortie (post Curl) data on screen -- Works
echo $result ;
// Input to the database -- Not working
$sqli = "LOAD DATA LOCAL INFILE '/tmp/sortie.csv'
INTO TABLE Sorties
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\''
LINES TERMINATED BY '\n'
" ;
$done=$link->query($sqli);
if (!$done) echo mysqli_error($sqli);
/*if (mysql_affected_rows() >= 1) {
$message = "The user was successfully updated!";
}
else
{
$message = "</br>The user update failed:</br> ";
$message .= mysql_error();
}
echo $message;
*/
}
$result->close();
$link->close();
return $rows;