Lethedethius Posted July 15, 2013 Share Posted July 15, 2013 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. } ?> Quote Link to comment Share on other sites More sharing options...
davidannis Posted July 15, 2013 Share Posted July 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.