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/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Get query results as their native data type? (/thread-67381.html)



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 );