-3

I am trying to query database using PHP. But I am getting the following error.

Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given in.

I cannot find what mistake I did. Can anyone point out what mistake have I did in this code?

<?php
$cn = new mysql();
 $cn->query("SELECT * FROM users WHERE name LIKE 'test'");


class mysql {


public function connect() {
    static $a = 0;
    if ($a==0) {   
        $a = mysql_connect("localhost:3306","root","vistaxp64");
        mysql_select_db("gecms");
    }
    return $a;


}
public function query($query) {
    $con=$this->connect();
    $qdata=mysql_query($query,$con)or die(mysql_error());
    $qresult=mysql_fetch_array($qdata,MYSQL_ASSOC) or die(mysql_error());
    return $qresult;
}



}
Ganesh Babu
  • 3,482
  • 10
  • 33
  • 63

1 Answers1

1

Check your return values. One of the mysql_ functions has returned boolean false, which they do when an error occurs, and you've blindly passed that false into another mysql_ function.

Also, if this is new code, stop using the mysql_ functions. They're deprecated and will be removed from the language soon. Consider PDO as an alternative.

user229044
  • 222,134
  • 40
  • 319
  • 330