2014-02-24 219 views
2

非關聯數組下面將返回array('a'=>123,'b'=>'abc','c'=>null)返回使用PDO

$sql='SELECT a,b,c FROM myTable WHERE id=123'; 
$stmt = $conn->query($sql); 
$rs= $stmt->fetch(PDO::FETCH_ASSOC); 

是否有可能返回array(123,'abc',null)沒有做這樣的事情array($rs['a'],$rs['b'],$rs['c'])

回答

3

由列號索引在結果集返回 ,數組嘗試PDO::FETCH_NUM

$sql='SELECT a,b,c FROM myTable WHERE id=123'; 
$stmt = $conn->query($sql); 
$rs= $stmt->fetch(PDO::FETCH_NUM); 
2
$rs = array_values($stmt->fetch(PDO::FETCH_ASSOC)); 

而且

PDO :: FETCH_NUM:返回了從0列