I am adding some php code for a website that is hosted for a couple of years now. I check everything on localhost and is just fine. But when I uploaded the new code to the host I got a warning:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/blah/blah
I have a class for mysql connection:
<?php
class ConnDB {
const SERVER = "localhost";
const USER = "admin";
const PASSWORD = "admin";
const NAMEDB = "mydb";
private $myConn;
private $status;
function __construct() {
$this->myConn = mysql_connect(self::SERVER, self::USER, self::PASSWORD);
if(!$this->myConn) {
$this->status = false;
} else {
if(!mysql_select_db(self::NAMEDB)) {
$this->status = false;
} else {
$this->status = true;
}
}
}
public function getMyConn() {
return $this->myConn;
}
public function getStatus() {
return $this->status;
}
}
Then I have my class that is using the connection:
<?php
require_once 'clase.conn.php';
class User extends ConnDB {
public function usersList() {
$query = "SELECT USER_ID, NAME, MAIL FROM USER";
$result = mysql_query($query, $this->getMyConn());
if(mysql_num_rows($result) == 0) {
return 0;
} else {
while($row = mysql_fetch_assoc($result)) {
$myarray[] = $row;
}
return $myarray;
}
}
I added a validation to check if result was true or false, thinking that was because the DB was empty. But when i added some rows through phpmyAdmin, i still got the same warning.
What could it be?