Lamez Posted November 17, 2010 Share Posted November 17, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2010 Share Posted November 17, 2010 (PHP 5 >= 5.3.0) What php version? Also - MySQL Native Driver Only Available only with mysqlnd. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135351 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 According to phpinfo(), I currently have installed is: 5.3.3-1. Do you know how I can find out what mysql driver I have installed? Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135357 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2010 Share Posted November 17, 2010 phpinfo Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135359 Share on other sites More sharing options...
JasonLewis Posted November 17, 2010 Share Posted November 17, 2010 If it's not available to you, you could just re-create the method manually with a while loop, which I'm sure you have considered. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135360 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 After I posted about the driver, I relized I could look at phpinfo() and I did. I am currently using '/var/run/mysqld/mysqld.sock'. I guess I am going to have to write my own, as suggested. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135365 Share on other sites More sharing options...
trq Posted November 17, 2010 Share Posted November 17, 2010 I am currently using '/var/run/mysqld/mysqld.sock'. That has no relation to your database driver. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135367 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 Oh no? Well let me look over at this info table again. Sometimes I can be so dumb. That is the socket. I still don't see it. Let me dig deeper. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135368 Share on other sites More sharing options...
JasonLewis Posted November 17, 2010 Share Posted November 17, 2010 Where exactly does it say the driver you are using? I was unable to find it... Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135372 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 Okay I found something called PDO and it says that the PDO driver is mysql. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135374 Share on other sites More sharing options...
JasonLewis Posted November 17, 2010 Share Posted November 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135376 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 That is cool, so say if my application is using PostgreSQL I could use the PDO functions, then I all of a sudden switch back to mysql I could use the same functions? That would be real handy when using my Database class. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135378 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2010 Share Posted November 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135379 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 Nope says not found. I guess I will be writing my own. Gosh it has been a while since I had to do this, I might be back for help. Lol, lets see how far I can get. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135381 Share on other sites More sharing options...
Lamez Posted November 17, 2010 Author Share Posted November 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135384 Share on other sites More sharing options...
JasonLewis Posted November 17, 2010 Share Posted November 17, 2010 That's how I would've suggested to do it. As really, that's what fetch_all() is doing. Quote Link to comment https://forums.phpfreaks.com/topic/218924-undefined-method/#findComment-1135386 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.