Bug #59842 mysqli_fetch_object() API function always converts field values to string
Submitted: 31 Jan 2011 13:06 Modified: 31 Jan 2011 13:13
Reporter: Cyber Ghost Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Storage Engine API Severity:S3 (Non-critical)
Version:5.1.49-1ubuntu8.1 OS:Linux (Ubuntu)
Assigned to: CPU Architecture:Any
Tags: API, mysqli_fetch_object

[31 Jan 2011 13:06] Cyber Ghost
Description:
I've just discovered that the mysqli_fetch_object() function will fetch data from a resultset into an object, but convert all field values into strings 

this way, when I use this function to retrieve an ID from a MEDIUMINT field (integer with a value of 1), it will be typecasted into a string of '1', which is not valid for this use

in my application (which uses CodeIgniter), when I retrieve multiple IDs this way and then try to use them in a subsequent query, CodeIgniter's escape() function will actually treat those IDs as strings and instead of creating query like "... WHERE id IN(1,2,3)" it will create: "... WHERE id IN ('1','2','3')" 

this has given me trouble with regards to table indexes usage (don't know why exactly, perhaps MySQL couldn't use an integer index with string values) and slowed down my queries

How to repeat:
use the mysqli_fetch_object() PHP function and see for yourself

Suggested fix:
return field values how they are stored in database rather than converted into strings
[31 Jan 2011 13:13] Ulf Wendel
The MySQL text protocol (non-prepared statements) is using strings for data encoding. PHP does not convert the strings it gets from MySQL into "native" types. This is how PHP mysqli has been designed and works ever since.