mysql - PHP MySQLi Fatal call to member function fetch_array() for a non-object -
yes...this question has been posted many times. here's example: fatal error: call member function query()on non-object. i've looked through many of these duplicate posts , cannot find solution
i pulled (working) code website ( nine-to-five )
but revised code (which different post) include code mentioned in post's answers , i'm still getting error:
// credentials $dbhost = "localhost"; $dbname = "qmsdb"; $dbuser = "root"; $dbpass = ""; // connection global $tutorial_db; $tutorial_db = new mysqli(); $tutorial_db->connect($dbhost, $dbuser, $dbpass, $dbname); $tutorial_db->set_charset("utf8"); // check connection if ($tutorial_db->connect_errno) { printf("connect failed: %s\n", $tutorial_db->connect_error); exit(); } // search $search_string = preg_replace("/[^a-za-z0-9]/", " ", $_post['query']); $search_string = $tutorial_db->real_escape_string($search_string); // check length more 1 character if (strlen($search_string) >= 1 && $search_string !== ' ') { // build query $query = 'select * compressors munpn "%'.$search_string.'%" or name "%'.$search_string.'%"'; // search $result = mysql_query($query); while($results = $result->fetch_array()) { $result_array[] = $results; } .... more code doesn't apply.... }
the error is: "fatal call member function fetch_array() on non object" , line points to:
while($results=$results->fetch_array()) {
i'm new php/mysql - on appreciated.
thanks!
.
mysql_*()
functions not, , have never been, object-oriented:
$tutorial_db = new mysqli(); ^----note "i" $result = mysql_query($query); ^-- note lack of "i" while($results = $result->fetch_array()) { ^^^^^^^^---- not object, because mysql_*() functions not objects
you cannot use db handle/object created in 1 db library (pdo, mysqli, mysql) in of other libraries. may talking mysql under hood, respective handles/objects not inter-compatible.
Comments
Post a Comment