I'm getting an error in PHP on a valid query, which executes fine when run directly from PHPMyAdmin.
Has anyone had a similar problem before and could point me in the right direction?
The error is below along with the function used the execute the query.
Array
(
[Error] => Invalid Query : SELECT * FROM users ORDER BY userDeleted ASC, userFullname ASC
)
Array
(
[Error] => Empty MySQL resource.
)
public function query($q){
if(empty($q)) $this->dbError('Empty MySQL Query.');
if($this->linkID == 0) $this->connect();
$temp = @mysql_query($q, $this->linkID);
if(!$temp) $this->dbError('Invalid Query : '.mysql_error().'<br />'.$q);
return $temp;
}
public function getUsers(){
$q = "SELECT * FROM users ORDER BY userDeleted ASC, userFullname ASC";
$result = $this->query($q);
Update: The database is connected to via:
private function connect(){
if(!$this->linkID){
$this->linkID = @mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
if(!$this->linkID) $this->dbError('Could not connect: ' . mysql_error());
$this->select_db();
}
return $this->linkID;
}
function select_db(){
if($this->linkID){
if(!@mysql_select_db(DB_NAME, $this->linkID)) $this->dbError('Can not use Database : ' . mysql_error());
}
}
linkID
valid? – DonCallisto Jan 29 '12 at 15:19mysql_select_db()
? – cb1 Jan 29 '12 at 15:20