Click to See Complete Forum and Search --> : error connecting to database


james19
02-21-2008, 07:05 AM
Hi
I got this code from the internet and cannot get it to work. It is supposed to connect to a database but it shows the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /web/rkhan19/ftpaccess/pub/includes/DbConnector.php on line 43

Does anyone know what could be wrong on line 43????????? Could it be that it only works on certain versions????????? Beloe is the code:

<?php

require_once 'something.php';

class DbConnector extends SystemComponent {

var $theQuery;
var $link;

function DbConnector(){

$settings = SystemComponent::getSettings();

$host = $settings['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];

$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
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);

}


}
?>



Your help would be very much appreciated:)

chazzy
02-21-2008, 07:35 AM
You'll have to show us where you're actually using this class that you get this error. Nothing's wrong with the class that I can see (other than maybe some missing error handling).

FrostBite
02-21-2008, 08:37 AM
The error is telling you that whatever variable you fed to the fetcharray function was not recognized as a valid result table. Check the spelling of your variable and remember that PHP's variables are case sensitive. If that's not the problem here's an example of how it should look:
$whatever = query("query string");
$result = fetcharray($whatever);
Hope this helps.
-Frosty

james19
02-21-2008, 09:29 AM
I found the error, I had some spelling mistakes thanks for the help:)