Click to See Complete Forum and Search --> : problems with database class


stickbomb
10-12-2007, 12:57 PM
ok for some reason i am getting warings saying that

Warning: supplied argument is not a valid MySQL result resource

when ever i try to run my scripts.

for all my functions.

this is my class

<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: Db
// Purpose: Connect to a database, MySQL version
///////////////////////////////////////////////////////////////////////////////////////
require_once 'core.php';

class Db extends Core {

var $theQuery;
var $link;

//*** Function: DbConnector, Purpose: Connect to the database ***
function Db(){

// Load settings from parent class
$settings = Core::getSettings();

require_once('mysql.php');

// Get the main settings from the array we just loaded
$host = $settings['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];

// Connect to the database
$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);

}

//*** Function: query, Purpose: Execute a database query ***
function query($query) {
$this->theQuery = $query;
return mysql_query($query, $this->link) or die(mysql_error());
}

//*** Function: getQuery, Purpose: Returns the last database query, for debugging ***
function getQuery() {
return $this->theQuery;
}

//*** Function: getNumRows, Purpose: Return row count, MySQL version ***
function getNumRows($result){
return mysql_num_rows($result);
}

//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {
return mysql_fetch_array($result);
}

//*** Function: close, Purpose: Close the connection ***
function close() {
mysql_close($this->link);
}

}
?>


Bascially I got this class directly from a tutorial that I am following so can some please help me figure out what is happening.

I am running it in a login class. I query the database to check for the user and if the rows is greater than 0 i validate otherwise i return to the login page.

NogDog
10-12-2007, 02:13 PM
It probably means that there is some sort of syntax error in your SQL, thus the call to mysql_query() is returning boolean false rather than a resource ID.

stickbomb
10-12-2007, 02:15 PM
no i check and it returns the boolean as true

NogDog
10-12-2007, 08:57 PM
Can you show us the code you use to call the class methods concerned, the exact error message it generates, and let us know which line in the source code is the line number cited in the error message?