Set MySQL fetch mode globaly

123 views Asked by At

We have recently migrated our application to a new server. Since our migration we are experiencing a lot of PHP message: PHP Fatal error: Call to undefined method stdClass::toArray() errors. I already found out, that this might be related to our SQL statements returning objects instead of arrays in the new environment. As we are using ADODB I also already found out, that the behaviour is because of $ADODB_FETCH_MODE. In our application it is set to ADODB_FETCH_DEFAULT . As the documentation states that means

The recordset is returned in the default provided by the PHP driver. Use of this value is not recommended if writing cross-database applications

So my assumption is the "new" PHP driver has a different configuration than the old one. But how can I find out what the default config of the PHP driver is and how to change it without changing actual application code?

Thanks!

1

There are 1 answers

0
dregad On

I would suggest to set the ADOdb fetch mode you need, instead of relying on the default. This can be done globally, e.g.

$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

Or per connection

$db->setFetchMode(ADODB_FETCH_ASSOC);