I am new to php and mysqli, and am attempting to put together a stats site for a game that I play. In a nut shell this code 1) looks up by user (via URL) the last X sorties (1 here but can change to any number), 2) Curl's that result, 3) places it into /tmp/sorties.csv, then 4) loads data local infle /tmp/sortie.csv to my database.
It does connect to the database (member table) and look up by member/player name (echos back in "updating for"), as well as the game information (shows 1 sortie per player who has data in the game database) --I've commented out the header so as to see what is echod back.
my site is hosted buy a 3rd party, but is using sql 5.5.32, php 5.3.13, and is a Linux/Debian platform. Any (and all) assistance is greatly appreciated, I actually wrote the vast majority of this by using some of the questions and answers provided here. I do have an only MySQL version of this code that is having the same error (started not working 2 days ago) and am hoping that updating to mysqli will correct the issue. The database fields do match both in number and data-type.
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://myurlforlookup.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;