I'm recently seeing some errors in the logs (1.9-dev) ERROR - 2017-11-08 11:00:05 --> Fatal Error - Call to a member function rowCount() on a non-object in /var/www/fuel/core/classes/database/pdo/connection.php on line 282
and
ERROR - 2017-11-08 12:50:27 --> Fatal Error - Call to a member function errorCode() on a non-object in /var/www/fuel/core/classes/database/pdo/connection.php on line 288
Both of these methods seem to be undefined ( should it be count() and error_info() ? ), just looks like some lines were missed during last DB core refactor ;)
Can't fully reproduce this atm, just letting you know that this doesn't look right.
The manual says: PDO::query() returns a PDOStatement object, or FALSE on failure.
From what I can see the situation FALSE isn't captured, but I wonder how this is possible, since we inject PDO::ERRMODE_EXCEPTION in the class constructor.
Could you debug it, by adding
if ( ! is_object($result))
{
logger(\Fuel::L_DEBUG, print_r($result, true));
logger(\Fuel::L_DEBUG, $sql);
}
before the break on line 198? And make sure you have logging configured to L_ALL?
DEBUG - 2017-11-13 09:05:13 --> DEBUG - 2017-11-13 09:05:13 --> INSERT INTO `categories` (`entid`, `categoryid`) VALUES ('455142', '24') ERROR - 2017-11-13 09:05:13 --> Fatal Error - Call to a member function rowCount() on a non-object in /var/www/fuel/core/classes/database/pdo/connection.php on line 287
There are few other queries causing it, different tables but always on insert.
That would be weird, that would render the DBAL useless for any application? What is the exact definition of that table? Could you dump the "create table" for it, including indexes?
So in general everything seems to be working fine, except these errors sometimes appear in logs. Usually on insert statements, affecting few different tables.
That particular tables is just linking table between 2 tables and definition looks like this (This is part of legacy codebase)
CREATE TABLE IF NOT EXISTS `ents_categories` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `entid` int(11) DEFAULT NULL, `categoryid` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `entid_categoryid` (`entid`,`categoryid`), KEY `entid` (`entid`), KEY `categoryid` (`categoryid`), CONSTRAINT `FK_ents_cc` FOREIGN KEY (`categoryid`) REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT `FK_ents_ce` FOREIGN KEY (`entid`) REFERENCES `ents` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=58210450 DEFAULT CHARSET=utf8;
No errors in todays log. I'll look again before afternoon.
did you add the debugging code to the PDO driver, as I suggested, so we can get more details on why the query doesn't return a PDOstatement object, and why it doesn't generate an Exception?
This is how it looks when I manually execute the script from CLI:
PHP Fatal error: Call to a member function rowCount() on a non-object in /var/www/fuel/core/classes/database/pdo/connection.php on line 287
Fatal error: Call to a member function rowCount() on a non-object in /var/www/fuel/core/classes/database/pdo/connection.php on line 287 Fatal Error - Call to a member function rowCount() on a non-object in COREPATH/classes/database/pdo/connection.php on line 287 Stack trace: #0 /var/www/fuel/core/bootstrap.php:71 Fuel\Core\Errorhandler::shutdown_handler() #1 [internal function] {closure}()
And in logs:
DEBUG - 2017-11-15 08:11:48 --> DEBUG - 2017-11-15 08:11:48 --> INSERT INTO `ents_categories` (`entid`, `categoryid`) VALUES ('643182', '41') ERROR - 2017-11-15 08:11:48 --> Fatal Error - Call to a member function rowCount() on a non-object in /var/www/fuel/core/classes/database/pdo/connection.php on line 287
And also it looks like this script always fails to execute, but at random places. Will try to provide more debug information
Ok what I've found is that the issue is caused by a persistent db connection, (so most likely the connection is suddenly dropped ), but still it does not explain why we can't capture this event as an exception.
I'm not familiar with PDO at the low level (I've always used some abstraction layers on top of that).
Could you dump $this->_config in the query() method, and check if it has an "attrs" key present? It must be there, and it must be an array, and the array must have a "3" => "2" entry.
If not, there is something going on that overwrites the config being set in __construct().
Also check your db.php, to make sure it doesn't pass a different value for \PDO::ATTR_ERRMODE in the connection attrs.