I'm moving a legacy php site over to a new host. There is a file that connects the php to the DB, but it is throwing an error on the new server. Everything seems to work.
The error is:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/jjrods/public_html/scripts/php/db.php on line 21.
Below is the script:
<?php
class dataBase {
public $conn;
public $result;
public $numrows;
//constructor - connects to db
public function __construct($query = null) {
$this->conn = mysql_connect('localhost', 'userName', 'passWord');
if ($this->conn == false)
return false;
mysql_select_db('new_Database');
return ($query) ? $this->sql($query) : $this->conn;
}//end __construct method
//write sql query to database
public function sql($query) {
$this->result = mysql_query($query);
if ($this->result)
$this->numrows = mysql_num_rows($this->result);
return $this->result;
}//end sql method
}//end dataBase class
?>
When I set this same site up locally, I didn't have these issues. Could it be a permissions issue?
So I've added the code from the page that errors. It seems to be doing a select as required by num_rows. Does this help anyone see why it throwing an error on one server, but not another?
if (isset ( $_GET ["id"] )) {
$db2 = new dataBase ( "SELECT * FROM car WHERE carId=" . $_GET ["id"] . " AND type='Muscle'" );
if ($db2->numrows > 0) {
// car found
$car = mysql_fetch_array ( $db2->result, MYSQL_ASSOC );
$db2 = new dataBase ( "UPDATE car SET views=" . ($car ['views'] + 1) . " WHERE carId=" . $car ['carId'] );
$db2 = new dataBase ( "SELECT location FROM pic WHERE carId=" . $car ['carId'] . " ORDER BY orderNum ASC" );
if ($db2->numrows > 0) {
// get pictures
while ( $row = mysql_fetch_array ( $db2->result, MYSQL_ASSOC ) ) {
$pics [] = $row ['location'];
}
} else
$isError = true;
Thanks for any ideas!