'Set MySQL fetch mode globaly
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!
Solution 1:[1]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dregad |