Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method PDOStatement::setFetchMode()

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?

like image 685
Daan Wilmer Avatar asked Nov 24 '17 09:11

Daan Wilmer


1 Answers

The solution was: try turning it off and on again — in this case the Apache server. Apparently something got corrupted in memory, and restarting the server fixed it.

I assumed this was already done by me shutting down my computer yesterday, after the problem appeared, and booting it again this morning. Now I know: windows 8 and up use a hybrid shutdown/hibernate instead of a real shutdown, so your apache service doesn't really get restarted if you think you restarted your PC.

Somehow this makes me feel so dumb...

like image 142
Daan Wilmer Avatar answered Nov 05 '22 19:11

Daan Wilmer