Jump to content

PHP Fatal error: Call to a member function query() on a non-object


Texan78
Go to solution Solved by Texan78,

Recommended Posts

I have a serious issue. I am not sure if I have been hacked or what but my site is completely messed up. I have a ton of these errors in the error log and I am not sure what is causing this. I don't recall this being part of the script

 

 

PHP Notice:  Undefined variable: mysqli in /home2/mesquiu0/public_html/stream/inc/streamNotify.php on line 9

PHP Fatal error:  Call to a member function query() on a non-object in /home2/mesquiu0/public_html/stream/inc/streamNotify.php on line 9

 

Which is referring to this line. 

//lets execute the query
$executingFetchQuery = $mysqli->query("SELECT `StreamStatus` FROM streamdb WHERE 1");
if($executingFetchQuery)
{
   while($arr = $executingFetchQuery->fetch_assoc())
   {
        $resultArr[] = $arr['StreamStatus'];//storing values into an array
   }
}

This is the full code. 

/* Lets connect to the database */     
//include('dbconn.php');
          
$resultArr = array();//to store results


//lets execute the query
$executingFetchQuery = $mysqli->query("SELECT `StreamStatus` FROM streamdb WHERE 1");
if($executingFetchQuery)
{
   while($arr = $executingFetchQuery->fetch_assoc())
   {
        $resultArr[] = $arr['StreamStatus'];//storing values into an array
   }
}


     $counts = array_count_values($resultArr);//lets count the results
     $online = $counts['true'];


// Let's assign the table some styles
     $divStyle = "padding:5px; margin:auto; margin-bottom:20px";


// Lets assemble the banners to display
     $notifyOffline = "<div class='alert alert-danger' style='{$divStyle}' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently no chasers streaming at this time.'> There are currently no chasers streaming at this time.</div>";


     $notify1Online = "<div class='alert alert-success' style='{$divStyle}' role='alert' data-toggle='tooltip' data-placement='top' title='There is currently 1 chaser streaming LIVE...'> There is currently 1 chaser streaming LIVE... </div>";


     $notifyOnline = "<div class='alert alert-success' style='{$divStyle}' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently ".$online." chasers streaming LIVE...'> There are currently ".$online." chasers streaming LIVE... </div>";




//lets display the banners
if ( $online == "1" ) {
    echo $notify1Online;
} elseif ( $online >= "2" ) {
    echo $notifyOnline;
} else {
    echo $notifyOffline;
}

Any and ALL help would be greatly welcomed. 

 

-THANKS!

Link to comment
Share on other sites

Again, the errors were happening BEFORE I commented out the code. I commented it out because it was throwing errors in the logs BEFORE commenting it out. It was also causing performance and resource issues on my host which was causing the page not to load. I commented it out in the script AND on the page it was being included on until I could resolve the issue. Once I did both those things the page loaded AND the errors went away. 

Link to comment
Share on other sites

This will stop that error

//    $executingFetchQuery = $mysqli->query("SELECT `StreamStatus` FROM streamdb WHERE 1");
//    if($executingFetchQuery)
//    {
//       while($arr = $executingFetchQuery->fetch_assoc())
//       {
//            $resultArr[] = $arr['StreamStatus'];//storing values into an array
//       }
//    }

However, it may cause others Edited by Barand
Link to comment
Share on other sites

Alright folks, a little less sarcasm if you don't mind.

 

The file has to be included. The variable has to be defined in that file (or some subsequently included file) and has to be done in the global scope. If either of those doesn't happen then $mysqli will be undefined and the code will not work.

Link to comment
Share on other sites

So I guess I just fantasized that someone gained root access via shell.

 

So I guess it is completely valid to comment out the entire query which renders the entire script useless. 

 

So I guess that if I uncomment the DB connection it will work perfectly fine with no errors correct? That is what you're saying right? 

 

Guess what, it is uncommented, the errors have returned. So now what all mighty know it all? What does your magic 8 ball have to say about that? 

 

Cool story bro? Yeah stick it keyboard warrior.

Edited by Texan78
Link to comment
Share on other sites

Guess what, it is uncommented, the errors have returned. So now what all mighty know it all? What does your magic 8 ball have to say about that? 

 

 

 

if you would post those exact errors w/line numbers, someone COULD help you with what's causing them, because the magic 8 ball we resort to using when someone doesn't think it's necessary to share specific information they have about a problem doesn't show us what you are seeing in front of you.. it's likely they are not exactly the same errors/line numbers as what you posted at the top of this thread.

Link to comment
Share on other sites

  • Solution

it's likely they are not exactly the same errors/line numbers as what you posted at the top of this thread.

 

 

They are EXACTLY the same line numbers. I copy and pasted them into a notepad to save for later then commented out the DB connection to stop it from making connections. 

 

This.... 

/* Lets connect to the database */     
//include('dbconn.php');

Has zero to do with the error as I still get the SAME error regardless if it is commented out or not. So ignore it even exists. Had I not posted that part at all then I am sure I would be getting completely different responses. 

 

No worries, thanks for the help. Its apparent no one is looking BEYOND what I am saying and only focusing on that being commented out instead of listening to what I am saying that it doesn't matter. I get the same error regardless even with waiting a couple hours which is plenty of time for the varnish cache to clear. 

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.