I'm getting the error Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in C:\wamp\www\******\include\Database.php on line 294 when I try to run this

function calcNumActiveUsers()
      $query = "SELECT * FROM ".TBL_ACTIVE_USERS;
      $result = $this->query($query); //just uses mysql_query
      $this->num_active_users = mysql_numrows($result);

As far as I can tell var_dump($result) should not be telling me that $result is true since I am running a select query. I'm getting this error on each function I call that accesses the database. Can anyone tell me what I'm doing wrong?

6 Years
Discussion Span
Last Post by nickles

Can you post the rest of code so we can see what is going on? From what you gave, I can't get you a definitive answer.

Also, mysql_numrows() is depreciated. Use mysql_num_rows() instead.


Ok, sorry about that.
Here's the constructor for the connection to the database. It's stored in $connection.

function MySQLDB()
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
      $this->num_members = -1;

Here's the query function. It mostly exists to save time while writing.

function query($query)
      return mysql_query($query, $this->connection) or die(mysql_error());

calcNumActiveUsers is called whenever a new session is started. If you need more please say so. There's just a good bit of code over a few files and I don't know if it's a good idea to post it all. And thanks for telling me about mysql_numrows(); I was unaware about that.


Must have been a logic problem I wasn't seeing. I changed the query function from the above to:

function query($query)
      $result = mysql_query($query, $this->connection) or die(mysql_error());
		return $result;

and everything started working.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.