0

The output of php -i | grep mysqlnd is:

Client API version => mysqlnd 5.0.11-dev - 20120503 - $Id: 40933630edef551dfaca71298a83fad8d03d62d4 Client API library version => mysqlnd 5.0.11-dev - 20120503 - $Id: 40933630edef551dfaca71298a83fad8d03d62d4 mysqlnd mysqlnd => enabled Version => mysqlnd 5.0.11-dev - 20120503 - Id: 40933630edef551dfaca71298a83fad8d03d62d Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password mysqlnd statistics => Client API version => mysqlnd 5.0.11-dev - 20120503 - $Id: 40933630edef551dfaca71298a83fad8d03d62d4

enter image description here

Which suggests it's loaded mysqlnd => enabled however all the database values are still coming out as strings, not converted to native PHP types:

$connection = new mysqli('127.0.0.1', 'root', '', 'my_database');

// Settings contains one tinyint field 'enabled'
$result = mysqli_query($connection, 'select * from settings');

var_dump(mysqli_fetch_array($result));

Result

array (size=1)
    'enabled' => string '1' (length=1)

Expected

array (size=1)
   'enabled' => int 1

Am I missing some config/any suggestions?

Gary Green
  • 22,045
  • 6
  • 49
  • 75
  • So show us piece of code and the error message you have please :-) – Alex Feb 08 '15 at 15:39
  • @KimAlexander I've added some code. Not really much to it. The mysqlnd driver should automatically convert to PHP data types where possible, but it's not. They're still coming out as strings even though according to PHP mysqlnd is loaded and enabled. – Gary Green Feb 08 '15 at 16:11
  • you will always get strings, I think that the reason is native sql engine, when it return data, there is no additional information about every column, just data. so it is always strings , either for datestamp. Did you see any other information over internet? if you saw any example if php code that shows that mysqli return INT or DATE formal - show me please :-) – Alex Feb 08 '15 at 16:19
  • @KimAlexander please read about what the mysqlnd driver is for. It's exactly for that reason. It's tightly coupled to the PHP so it can detect mysql data types and convert to PHP types. – Gary Green Feb 08 '15 at 16:21

1 Answers1

0

So it seems that mysqlnd is only available when your using PDO.

I've changed my code to use PDO and also ensured that emulated prepares is off (otherwise it still will return strings). Now it converts to PHP data types! :-)

$pdo = new PDO('mysql:host=127.0.0.1;dbname=my_database', 'root', '');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$result = $pdo->query('select * from settings');

var_dump($result->fetch());

Result

array (size=1)
  'enabled' => int 1
Gary Green
  • 22,045
  • 6
  • 49
  • 75