I am trying to do a simple MySQL query using my db class, but for some reason I am having issues with getting the query through using my db class. If I hard code the db call bypassing the class, it works fine. Here is the class:

// Class: DbConnector
// Purpose: Connect to a database, MySQL version

class dbconnector extends systemComponent {

var $theQuery;
var $link;

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

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

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

	// Connect to the database
	$this->link = mysql_connect($host, $user, $pass);
	register_shutdown_function(array(&$this, 'close'));


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

//*** 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() {


systemComponent.php simply feeds the class the db login, password, user, etc info.

Here is how I am calling it.

$db = new dbConnector();
$getAll = $db->query("SELECT * from `cmsnews`");
$rows = $db->getNumRows($getAll);
echo $rows;
echo $db->getQuery();

The class correctly does the getQuery() call and it shows the current query, however I get the

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\webs\etalenttraks\includes\dbconnector.php on line 45"

from doing the getNumRows method. Am I missing something here?


7 Years
Discussion Span
Last Post by xmaddness

That returns

Table 'dbName.dbTable' doesn't exist'

And I instantly checked the user, pass, dbname, dbhost file, and well, it turns out it is pointing to my online server, rather than my localhost!

Wrong dbinfo!


I need some lunch >_<


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.