Jump to content

[SOLVED] Supplied Argument Is Not A Valid MySQL Resource


Altec

Recommended Posts

Well, I knew this was not going to work, but I had to try. Currently I'm sending my queries through this class I made:

class dbConnection {

public $table_s = NULL;

function __construct(/*$link_ident = NULL,*/$server = 'localhost',$user = 'meh',$pass = 'meh') {
	if(!mysql_connect($server, $user, $pass)) {
		throw_error('Error connecting to database: '.mysql_error(),E_ERROR);
		exit;
	}
	/*if($link_ident == NULL) {

		if(!mysql_connect($server,$user,$pass)) {
			throw_error('Error connecting to database: '.mysql_error(),E_ERROR);
			exit;
		}
	} else {

	}*/
}

function select($database,$table = 'false') {
	if(!mysql_select_db($database)) {
		throw_error('Error selecting table "'.$database.'": '.mysql_error(),E_ERROR);
		exit;
	}
	($table == 'false') ? $this->table_s = NULL : $this->table_s = $table;
}

function query($mysql_query) {
	if(!mysql_query($mysql_query)) {
		throw_error('Error sending data to database: '.mysql_error(),E_ERROR);
		exit;
	}

	return true;
}

function disconnect() {
	mysql_close();
}
}

In the future, I'm hoping to extend this class for other database types, but for right now I'm focusing on the core of the script.

 

Anyway, I'm trying to do this:

$d = mysql_fetch_assoc($comm_conn->query($query));

Which returns this:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in index.php on line 15

How can I resolve this error without losing the class?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.