0

I am trying to get numbers to output as such when fetching data from a MySQL database on a site hosted on Hostgator. PHP 7.0, MySQL - Server version: 5.5.48-37.8 - Percona Server (GPL), Release 37.8, Revision 727, Database client version: libmysql - 5.1.73.

PDO parameters:

[
    PDO::ATTR_EMULATE_PREPARES => false,
    PDO::ATTR_STRINGIFY_FETCHES => false,
]

Yet even with these attributes, it still returns integers as strings. How can I fix this?

jurchiks
  • 1,354
  • 4
  • 25
  • 55

1 Answers1

1

Have you looked at this SO question: How to get numeric types from MySQL using PDO? Also, make sure you have mysqlnd installed and activated. Look at php --info under pdo_mysql.

If it is, the output should look like this:

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.10 - 20111026 - $Id:___ $

If that isn't installed, install it with this:

apt-get remove php5-mysql
apt-get install php5-mysqlnd
service apache2 restart

If that doesn't fix it, the issue is likely in the code you haven't shown us.

Hope this helps! Cheers!

Community
  • 1
  • 1
FelisPhasma
  • 332
  • 5
  • 13
  • >hosted on Hostgator... The issue is not in the code. It works on my home machine, but not on the server, because the fetched ints are converted there. – jurchiks Jun 29 '16 at 18:21
  • @jurchiks http://support.hostgator.com/articles/php-modules – FelisPhasma Jun 29 '16 at 18:23
  • It looks like mysqlnd is installed on your home machine but not host gator then. – FelisPhasma Jun 29 '16 at 18:23
  • Is there no way to fix this without trying to get Hostgator to install mysqlnd? – jurchiks Jun 29 '16 at 18:25
  • And just to clarify, the query's result is returned by hostgator, php does the interpreting of that result. – FelisPhasma Jun 29 '16 at 18:25
  • On hostgator, do you have control over the php modules? – FelisPhasma Jun 29 '16 at 18:25
  • I would recommend contacting hostgator support and asking them. – FelisPhasma Jun 29 '16 at 18:27
  • There is a list of PHP PEAR modules only, not extensions. Doesn't look like this can be changed. Still waiting on the line to get to their support. – jurchiks Jun 29 '16 at 18:33
  • @jurchiks Well good luck! If it turns out you can't get the module, I can work with you to find another solution! – FelisPhasma Jun 29 '16 at 22:01
  • Well, pretty much the only simple solution is to use intval() where an int is required... A considerably more complex one would be to check actual table datatypes on every select and cast them to appropriate PHP datatypes, but screw that hassle. Not worth it for the project I'm working on. Anyway, planning to move the project to a different server, so I'll just look for one that has mysqlnd available/default. – jurchiks Jun 30 '16 at 20:25