Hey guys & gals.
I'm following a tut on the front page (Creating a CMS System - Peter Z.).
I have gotten to the part where he discusses testing to see how your dbConnector class is working. Well, I have the followign scripts and I get the ever infamous:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
SystemComponent.php
<?php
class SystemComponent{
var $cfg;
function getSettings(){
$cfg['siteDir'] = $_SERVER['DOCUMENT_ROOT'].'/install_folder/';
$cfg['dbHost'] = 'localhost';
$cfg['dbUser'] = 'dbuser';
$cfg['dbPass'] = '*******';
$cfg['dbName'] = 'tablename';
return $cfg;
}
}
?>
dbConnector.php
<?php
require_once 'systemcomponent.php';
class DbConnector extends SystemComponent{
var $theQuery;
var $link;
function DbConnector(){
$cfg = SystemComponent::getSettings();
$dbhost = $cfg['dbHost'];
$dbuser = $cfg['dbUser'];
$dbpass = $cfg['dbPass'];
$dbname = $cfg['dbName'];
$this->link = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname); register_shutdown_function(array(&$this, 'close'));
}
function query($query){
$this->theQuery = $query;
return mysql_query($query, $this->link);
}
function fetchArray($result){
return mysql_fetch_array($result);
}
function close(){
mysql_close($this->link);
}
}
?>
Testit.php
<?php
require_once('includes/dbconnector.php');
$connector = new DbConnector();
$result = $connector->query("SELECT * FROM `categories` ORDER BY `id`");
$row = $connector->fetchArray($result);
echo $row['id'].'.) '.$row['cateogry'].' :: '.$row['description'];
?>
Yes there is information in the database (2 rows). It's not returning anyting. When I echo different variables holding the query, only the var $query displays anything.
Can anyone see what is going on here? I have no clue as to what is goign wrong. I have tried editing area, and it just won't work.
Anyhelp is appreciated.
~Brett