有没有办法只使用pdo从select中获取值?
select city from customer
我想要一个只有城市值的数组没有索引'city',例如:
['milano','rome']
THX。
答案 0 :(得分:2)
$sth = $dbh->prepare("select city from customer");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_COLUMN, 0);
var_dump($result);
答案 1 :(得分:0)
这样的事情:
$cities = array();
$stmt = $pdo->prepare("SELECT city FROM cities");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$cities[] = $row['city'];
}