php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67441 mysqli_result::fetch_array() returns an array with all values in string type.
Submitted: 2014-06-14 04:49 UTC Modified: 2014-06-14 12:55 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: taopy at qq dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.5.13 OS: FreeBSD/CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: taopy at qq dot com
New email:
PHP Version: OS:

 

 [2014-06-14 04:49 UTC] taopy at qq dot com
Description:
------------
CREATE TABLE table_name (
  id int not null primary key
);

Obviously, field `id` is an integer.
But whatever your field's type is, mysqli extension returns you string type.

P.S.: I tried sqlite3 extension, no such a problem, it returns int value.

Test script:
---------------
$db = new \mysqli('host', 'user', 'pass', 'dbname');
$res = $db->query('select * from table_name;');

$arr = $res->fetch_array(MYSQLI_ASSOC);
var_dump($arr);

$arr->free();
$db->close();

Expected result:
----------------
It should returns an array like:

array(1) {
  ["id"]=>
  int(1)
}

Actual result:
--------------
array(1) {
  ["id"]=>
  string(1) "1"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-14 12:55 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2014-06-14 12:55 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

MySQL's network protocol is string based. We won't convert it but let PHP's type system handle this when needed.

(MySQL prepared statements would use a sightly different protocol thus when doing prepare/execute you'd get an integer ...)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 11:01:29 2024 UTC