我想在Drupal 8中获得许多用户。
$connection = \Drupal::database();
$query = $connection->query('SELECT count(*)' FROM {users});
$results = $query->fetchAll();
$results = json_decode(json_encode($results),true);
print_r($results);
显示输出:
Array([0]=>Array([count(*)]=>10));
但我的网站目前只有2位用户。
这有什么不对?
答案 0 :(得分:0)
此解决方案对我有用。
$sql = "SELECT name, quantity FROM {goods} WHERE vid = :vid";
$result = db_query($sql, array(':vid' => $vid));
if ($result) {
while ($row = $result->fetchAssoc()) {
// Do something with:
// $row['name']
// $row['quantity']
}
}
或
$query = db_query("SELECT nid, title FROM {node}");
$records = $query->fetchAll();
foreach ($records as $record) {
// Do something.
}