Jump to content

a game masterserver in php that is having issues


Lethedethius

Recommended Posts

the error I'm getting:

Fatal error: Call to a member function fetch_array() on a non-object in /home/lethonli/public_html/masterserver/index.php on line 29

 

the code:

 

<?php  
       
require("sql.php");  
      
       function 
registerServer($con$IP$exp) {  
          
$added 0;  
          
$IP $con->real_escape_string($IP);  
          
$exp $con->real_escape_string($exp);  
          
//  
          
$result sqlCall($con"SELECT * FROM Servers");  
          while(
$row $result->fetch_array(MYSQLI_ASSOC)) {  
             
$rowIP $row["IP"];  
             if(
strcmp($IP$rowIP) == 0) {  
                
$added 1;  
                
sqlCall($con"UPDATE Servers SET UTCExpry='$exp' WHERE IP='$IP'");  
                
//server is already there, add 5 more minutes to it's live time  
                
echo "$"."PGDUPDATE ".$IP;  
                break; 
// break the loop here, we have finished our work!  
             
}  
          }  
          if(
$added == 0) {  
             
//server is not in the list, add it now  
             
sqlCall($con"INSERT INTO Servers (IP, UTCExpry) VALUES ('$IP', '$exp')");  
             echo 
"$"."PGDREGISTER ".$IP;  
          }  
       }  
      
       function 
optimizeDatabase($con) {  
          
$result sqlCall($con"SELECT * FROM Servers");  
          while(
$row $result->fetch_array(MYSQLI_ASSOC)) {  
             
$utc $row["UTCExpry"];  
             
$ip $row["IP"];  
             if(
time() > $utc) {  
                
$result2 "DELETE FROM Servers WHERE IP='$ip'";  
                
sqlCall($con$result2);
                  
             }  
          }  
       }  
         
       
$con sqlLogin("...""...""...") or die("$"."INTERNAL_ERROR");  
       
$mode $_POST["mode"];  
       switch(
$mode) {  
          
//server add request  
          
case 1:  
             
$currentUTC time();  
             
$minutes 5;  
             
$expryUTC $currentUTC + ($minutes 60);  
             
//  
             
if(!isSet($_POST["port"])) {  
                
$port 28000;  
             }  
             else {  
                
$port $_POST["port"];  
             }  
             
$ipAddress $_SERVER['REMOTE_ADDR'] .":"$port;  
             
//Add the new server  
             
RegisterServer($con$ipAddress$expryUTC);  
             
//  
             
optimizeDatabase($con);  
             return;  
          
//list request  
          
case 2:  
             
optimizeDatabase($con);  //clear old servers out before sending the list to the player  
             
echo "$"."PGD"."$"."LIST ";  
             
$result sqlCall($con"SELECT * FROM Servers");  
             while(
$row2 $result->fetch_array(MYSQLI_ASSOC)) {  
                echo 
"$".$row2["IP"]." ";//space after each server in the list!  
             
}   
             return;  
          default:  
             
optimizeDatabase($con);  //PGD will access this script every 15 - 30 minutes to optimize it automatically.  
       
}  
    
?> 

The line

$result = sqlCall($con, "SELECT * FROM Servers"); 

is running the query that the fetch_array tries to get the data from. If the query succeeds, the variable $results contains an object. If not, it contains a boolean false. So the query is failing. You need to see what error mysql is returning and fix that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.