2

I have a project made in flex, using PHP data services to access an SQL server database, and I need to convert it to MySQL, I have changed all my PHP services from sqlsrv to mysqli.
Something like this:

$this->connection = mysqli_connect(SERVER,USERNAME,PASSWORD,DATABASE); // Start Connection
$ssqlstring = "select * from Users";
$runssql = mysqli_query($this->connection, $ssqlstring);
while($user = mysqli_fetch_array($runssql)) 
{
  $users[$user["ID"]] = $user;
}
return $users;

It worked fine on sqlsrv but with mysqli it returns to flex the INT, BIT, or DATE values as string

the main Datatypes on MySQL are INT, VARCHAR, BIT(1), DATETIME, DATE (same as sqlsrv)
and on the flex the return types are mainly as object[]

Dharman
  • 30,962
  • 25
  • 85
  • 135
Joaolvcm
  • 1,983
  • 3
  • 20
  • 24
  • possible duplicate of [Accessing PHP MySQLI predefined constants via respective value?](http://stackoverflow.com/questions/6537212/accessing-php-mysqli-predefined-constants-via-respective-value) – Wrikken Feb 24 '12 at 18:03
  • Does this answer your question? [How do I make sure that values from MySQL keep their type in PHP?](https://stackoverflow.com/questions/14180981/how-do-i-make-sure-that-values-from-mysql-keep-their-type-in-php) – Dharman May 13 '20 at 00:13
  • Does this answer your question? [MySQL integer field is returned as string in PHP](https://stackoverflow.com/questions/5323146/mysql-integer-field-is-returned-as-string-in-php) – tim Oct 17 '20 at 23:27

1 Answers1

4

from the manual

Returns an array of strings that corresponds to the fetched row or NULL if there are no more rows in resultset.

There are relatively few native types in PHP, in short, possibles are INT, FLOAT and STRING (where STRING is the default for all the rest, like BIT and DATE etc.). PDO is a bit better at using more close-to-actual types, but still defaults to strings a lot. In mysqli, you could use mysqli_result_fetch_fields to get the type of field returned, and cast it to a desired format, see also the MYSQLI_TYPE_* constants.

Wrikken
  • 69,272
  • 8
  • 97
  • 136
  • 1
    based on your response i found this http://stackoverflow.com/questions/6537212/accessing-php-mysqli-predefined-constants-via-respective-value , thank you – Joaolvcm Feb 24 '12 at 17:59