Jump to content

Undefined Method?


Lamez

Recommended Posts

I have an error that I seem to find curious. Let me explain what I have. I have a Database class that has a function (the culprit) that is called fetchAll. It is suppose to call the mysqli method mysqli_result::fetch_all(). This method does exist, I have looked it up: The PHP Manual, however do note the last comment on the page, it describes my problem, but does not explain how I can fix it. Now, here is my error:

 

Fatal error: Call to undefined method mysqli_result::fetch_all() in /var/www/core/includes/Database.php on line 36

 

Here is line 36:

$row = $this->result->fetch_all($mode);

 

Here is the entire function, or is it called a method since it is in a class?

	function fetchAll($mode = 'MYSQLI_ASSOC'){

		$row = $this->result->fetch_all($mode);

		return !empty($row) ? $row : array();//if not empty return row, else return an array?

	}

 

I could post the entire class, but I think it might be irrelevant so I will spear you guys.

 

Do you guys think you might be able to help me out?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/218924-undefined-method/
Share on other sites

PDO is an abstraction layer. It just provides a set of easy functions that work on any database you use. So that's just saying you have the MySQL PDO driver installed, not sure if that is you're actual MySQL driver. I prefer PDO over MySQLi.

Link to comment
https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135376
Share on other sites

Since the error message indicates you are using a mysqli_result object, the PDO information out of the phpinfo() has nothing to do with the current problem. Also, the mysqlnd (mysql Native Driver) sits between either the mysql/mysqli extension and the database itself.

 

You should be looking (searching on the phpinfo() output page) for a reference to mysqlnd

Link to comment
https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135379
Share on other sites

After quick thought, I figured it out. I have tested it and it seems to work, here is how I solved my problem:

 

	function fetchRow(){

		return $this->result->fetch_assoc();

	}

	function fetchAll($mode = 'MYSQLI_ASSOC'){

		/*$row = $this->result->fetch_all($mode); */

		//return !empty($row) ? $row : array();//if not empty return row, else return an array?

		$row = array();

		while($f = $this->fetchRow())

			$row[] = $f;

		return !empty($row) ? $row : array();

	}

 

Any suggestions?

 

 

Note: I also don't code with double spaces. I am using Linux and I think it might have something to do with the text-encoding, but I am not sure.

Link to comment
https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135384
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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