Jump to content

PHP Fatal error: Call to a member function prepare() on null


bbmak
Go to solution Solved by Jacques1,

Recommended Posts

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;
		
	}
Link to comment
Share on other sites

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 by bbmak
Link to comment
Share on other sites

  • Solution

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 by Jacques1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.