1

I have problem with mysqli. When I query the data, mysqli always returns a string.

In my database there is a table "model":

CREATE TABLE Models
(
    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    name TEXT,
    PRIMARY KEY (id)
) ;

My PHP code

$mysqli = new mysqli($host,$username,$password,$database);
$resultSql = $mysqli->query('SELECT * FROM models');

$resultArray = array();
while($row =  $resultSql->fetch_assoc()) {
     array_push($resultArray,$row);
}
print(gettype($resultArray[0]['id']));

And print() returns to me "string". But field "id" in the database has integer data type. I was looking for some settings, but could not find it.

I tried using PDO, but I ran into the same problem. If you know the solution for PDO, I'll be happy.

Can you help me?

Thanks.

Nikolay Bildeyko
  • 109
  • 4
  • 10

1 Answers1

1

I was looking for some settings, but could not find it.

You have to use mysqlnd-based prepared statements to get ints.

If you know the solution for PDO, I'll be happy.

Again, mysqlnd-based PDO installation is required

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345