$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類型沒錯,可是為什麼資料查出來後類型都變了?
回複內容:
$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類型沒錯,可是為什麼資料查出來後類型都變了?
類似問題參考
http://segmentfault.com/q/1010000002957162