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.  
       
}  
    
?> 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.