hi.
i am trying to use data from a online game that i am playing.
i have successfully create a Mysql database and the php code(took the code from the game forum), but i still get an errore that i dont understand..:
here is the errore:
mysql row count = 47788
Warning: fopen(/host_directory/players.txt) [function.fopen]: failed to open stream: No such file or directory in /home/asterix0/public_html/PHP/database_connect.php on line 56
Warning: fgets(): supplied argument is not a valid stream resource in /home/asterix0/public_html/PHP/database_connect.php on line 58
Warning: fclose(): supplied argument is not a valid stream resource in /home/asterix0/public_html/PHP/database_connect.php on line 62
players.txt line count = 0
now my database does get filled from the data url file and i did create the file players.txt which is in the same directory.
here is the code:
<?php
$cachedir="/host_directory/";
if (readCache($cachedir . 'players.gz', 86400) != 2) { /* 1 day */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://fr15.grepolis.com/data/players.txt.gz');
$fp = fopen('players.gz', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec ($ch);
curl_close ($ch);
fclose($fp);
uncompress("players.gz","players.txt");
$count=0;
include("dbinfo.inc.php");
mysql_connect($db_host,$db_user,$db_pwd);
@mysql_select_db($db_base) or die( "Unable to select database");
$query = "TRUNCATE TABLE ".$tableT1;
$query = @mysql_query($query);
$handle = fopen ('./players.txt', 'r');
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
{
if ($count == 1000) {
$query = @mysql_query($query);
$count = 0;
}
$count++;
if ($count == 1) {
$query = "INSERT INTO ".$tableT1." VALUES ('". implode("','", $data) ."')";
} else {
$query .= ",('". implode("','", $data) ."')";
}
}
$query = @mysql_query($query);
$query = "SELECT * FROM `".$tableT1."`";
$thing = mysql_query($query);
echo "mysql row count = ".mysql_numrows($thing)."<br>";
mysql_close();
}
echo "players.txt line count = ".countLines($cachedir.'players.txt')."<br>";
function countLines($filepath) {
$handle = fopen( $filepath, "r" );
$count = 0;
while( fgets($handle) )
{
$count++;
}
fclose($handle);
return $count;
}
function readCache($filename, $expiry) {
if (file_exists($filename)) {
if ((time() - $expiry) > filemtime($filename)) { return 1; }
return 2;
}
return 0;
}
function uncompress($srcName, $dstName) {
$string = implode("", gzfile($srcName));
$fp = fopen($dstName, "w");
fwrite($fp, $string, strlen($string));
fclose($fp);
}
?>
my goal is to create a game tool ,like a distance and time calculator to syncronise attaks,to create as well some maps for the game which will update themself.
i know this is really big for a noob like me🙂
but i really want to try...
thanks in advance for your help🙂