bbmak Posted March 1, 2017 Share Posted March 1, 2017 Hi Trying to implement with the prepare statement, and it gives me this error. "PHP Fatal error: Call to a member function prepare() on null." Anybody knows what is wrong? function listMerchant() { $merchant = array(); $merchantList = $this->mysqli->prepare("SELECT * FROM core_merchant"); $merchantList->execute(); while($merchantRows = $merchantList->fetch_array()) { $merchant[] = $merchantRows; } $merchantList->close(); return $merchant; } Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 1, 2017 Share Posted March 1, 2017 It means there's no such thing as $this->mysqli. Either that attribute doesn't even exist, or you've failed to assign a connection to it. Quote Link to comment Share on other sites More sharing options...
bbmak Posted March 1, 2017 Author Share Posted March 1, 2017 (edited) ummm.... I have other functions in the class using $this->mysqli-query(), and they work fine. Somehow the prepare() is not working. I am new to prepare(), and not sure my syntax is correct or not. Edited March 1, 2017 by bbmak Quote Link to comment Share on other sites More sharing options...
bbmak Posted March 1, 2017 Author Share Posted March 1, 2017 I go back and check my connection. The file include the wrong path for the connection folder. I fixed that, and now I got this. PHP Fatal error: Call to undefined method mysqli_stmt::fetch_array() Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted March 1, 2017 Solution Share Posted March 1, 2017 (edited) A prepared statement doesn't have a fetch_array() method. Read the manual on how prepared statements work. Actually, you don't need this at all, because you have no external input. The entire method can be boiled down to function listMerchant() { return $this->mysqli->query('SELECT col1, col2, ... FROM core_merchant')->fetch_all(MYSQLI_BOTH); } Edited March 1, 2017 by Jacques1 Quote Link to comment Share on other sites More sharing options...
bbmak Posted March 1, 2017 Author Share Posted March 1, 2017 Thank you guru. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.