PHP使用fetch_assoc()获取查询结果时数据类型都变了
黄舟
黄舟 2017-04-10 16:10:50
0
1
686
        $res=$this->conn->query($sql) or die('execute sql error:'.$this->conn->error);
        $arr=array();
        $i=0;
        while ($row=$res->fetch_assoc()){
            $arr[$i]=$row;
            $i++;
        }
        $res->free();
        $this->conn->close();
        return $arr;

上面这一段是查询的,结果都拿到了,可是当我打印结果数组是,发现数据全都变成了字符串

array(3) {
  [0] => array(3) {
    ["id"] => string(1) "1"
    ["name"] => string(8) "zhangsan"
    ["age"] => string(2) "23"
  }
  [1] => array(3) {
    ["id"] => string(1) "2"
    ["name"] => string(4) "lisi"
    ["age"] => string(2) "18"
  }
  [2] => array(3) {
    ["id"] => string(1) "3"
    ["name"] => string(6) "wangwu"
    ["age"] => string(2) "20"
  }
}

我检查了数据库,id和age这两个字段确实是int类型没错,可是为什么数据查出来后类型都变了?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
Peter_Zhu

类似问题参考
http://segmentfault.com/q/1010000002957162

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template