Hi,
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
	  var_dump($result);
      $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?

Recommended Answers

All 3 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.