Hello,
I've been working on a CMS that utilizes a MySQL Database for storing information. However, I am running into an error and I can't figure it out for the life of me. Any help would be greatly appreciated!
Here's the error it get:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/ccamaj/public_html/mm/includes/DbConnector.php on line 50
Here's my DbConnector.php
<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: DbConnector
// Purpose: Connect to a database, MySQL version
///////////////////////////////////////////////////////////////////////////////////////
require_once 'SystemComponent.php';
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['dbusername'];
$pass = $settings['dbpassword'];
// Connect to the database
$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
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() {
mysql_close($this->link);
}
}
?>
The DbConnector.php checks SystemProcedure.php for the database info, here's the coding in the SystemProcedure.php:
<?php
class SystemComponent {
var $settings;
function getSettings() {
// System variables
$settings['siteDir'] = '/usr/home/ccamaj/public_html/mm/';
// Database variables
$settings['dbhost'] = 'localhost';
$settings['dbusername'] = 'ccamaj_news';
$settings['dbpassword'] = 'news';
$settings['dbname'] = 'ccamaj_news';
return $settings;
}
}
?>
Again, thanks!
Chris