I'm working with drupal 7, on PHP 7, on Xampp on Windows, and suddenly I start getting the following error:
Call to undefined method DatabaseStatementBase::setFetchMode()
Where DatabaseStatementBase extends PDOStatement directly. When reducing the code to the following minimum:
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'test', 'test');
$pdostatement = $dbh->prepare('SELECT * FROM items WHERE id=?');
$pdostatement->setFetchMode(PDO::FETCH_CLASS);
$success = $pdostatement->execute([1]);
// do stuff...
It still throws an error on the line regarding setFetchMode. When I comment that line out, no error is thrown, but I get an associative array instead of an object — not what drupal expects. Especially since setFetchMode should exist (see http://php.net/manual/en/pdostatement.setfetchmode.php)
Finally, when I then try to find the methods of the $pdostatement
using reflection, I get garbage for some of the names — or, more accurately, the name seems about 1.5MB long and contains a lot of unreadable characters and some of the method names, as if an entire DLL was loaded in there or something. Here's an example of what var_dump
(php7 & xdebug) make of it:
object(ReflectionMethod)[17]
public 'name' => string '����&������p�aZ������������ ���bindParam�������{�nZ���������������setAttribute����f�kZ����������j����FETCH_ORI_FIRST�a�pZ���������q��
���CURSOR_SCROLL���l�}Z���������������fetchColumn������zZ��������������wph�����&��������Z���������������debugDumpParams���Z��������.�����children����������Z������������wphX����&��������Z��������(��
���nextrowset��������Z������������
���__toString������ ��Z������������wph(����&������4��Z��������'... (length=1752201104)
public 'class' => string 'PDOStatement' (length=12)
How can I fix this?
get_class_methods
yiels the same result. However, usingfetchObject
isn't a valid workaround — remember, I'm working with drupal here, I'd have to change a lot of code. Besides, production still works. – Mansfield