我有这个代码:
$sql = new PDO('mysql:host=localhost;dbname=b', 'root', 'root');
$f = $sql->query('select * from user');
$sql->setFetchMode(PDO::FETCH_ASSOC);
while($row = $f->fetch()){
print_r($row);
}
输出是
Array
(
[id] => 1
[name] => turki
[mail] => ablaf
[pass] => 144
)
Array
(
[id] => 2
[name] => wrfwer
[mail] => fwerf
[pass] => werf
)
这就是我真正想要的。但如果我这样做
<?php
$sql = new PDO('mysql:host=localhost;dbname=b', 'root', 'root');
$f = $sql->query('select * from user');
$f->setFetchMode(PDO::FETCH_ASSOC);
print_r($f->fetch());
?>
输出是
Array
(
[id] => 1
[name] => turki
[mail] => ablaf
[pass] => 144
)
它有一个结果,但我在表中有两行;这是为什么?