How to "disable" mysqlnd native type cast support in PHP

521 views Asked by At

Backstory

We are migrating our projects codebase from PHP 5.3 to PHP 7.0 on a CentOS 6 platform.

The old stack uses Apache with PHP 5.3 libphp module + libmysql and the new stack uses Nginx with PHP 7.0 FPM + mysqlnd.

We have them configured to run in parallel to easily switch over to the new version when everything is prepared (thanks to SCL).

The problem(ish) part

One nice feature with mysqlnd is that it is able to automatically return us database fields in the correct type that are used in the database (VARCHAR as string, MEDIUMINT as integer etc).

Though, sadly, it is kind of working against us.

One part of the project is to provide an API service to native apps, both Android and iOS, to communicate with other various services in our system.

Due to some bad design decisions in the past years (out of my control), some integers are sent to mobile apps as strings because of how libmysql supported this. So when we switched over the PHP systems, it started to break our mobile apps because the types did not match anymore.

To avoid any further delays in the upgrade as it might take months for our end-users to upgrade their mobile apps which would have these fixed, we started to look into ways how we could somehow go back to the old way of returning everything as string from the database in mysqlnd.

So far my googling hasn't yielded any informative results. I've also started thinking that this is a design aspect of mysqlnd and it can't really be achieved.

So finally to my question

I'm guessing there are quite a few folks who have gone through similar upgrade processes, so I would like to ask any recommendations on the obstacles you may have encountered.

Is it possible to "disable" automatic type casting to PHP? Are there any viable workarounds to retain codebase support for mobile apps (besides going through the API codebase and casting everything back to strings)?

0

There are 0 answers