CodeIgniter Forums
Get query results as their native data type? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Get query results as their native data type? (/showthread.php?tid=67381)



Get query results as their native data type? - dimas - 02-16-2017

Hi,

I've a MySQL 5.6 database with an PHP7/Codeigniter3.1 app querying it. When I do a query and get the results with $query->get()->result_array() the array values are all strings and in the database some fields are defined as int.

Another app querying a SQL Server works ok with native data types.

I tried 'mysqli' and 'pdo' drivers, both with mysqlnd enabled.

Any tips?

THx


RE: Get query results as their native data type? - jonathanq - 02-16-2017

(02-16-2017, 07:31 AM)dimas Wrote: Hi,

I've a MySQL 5.6 database with an PHP7/Codeigniter3.1 app querying it. When I do a query and get the results with $query->get()->result_array() the array values are all strings and in the database some fields are defined as int.

Another app querying a SQL Server works ok with native data types.

I tried 'mysqli' and 'pdo' drivers, both with mysqlnd enabled.

Any tips?

THx

Always return string types, if you send request in json can do it some like that: json_encode( $results , JSON_NUMERIC_CHECK );