gpt4 book ai didi

php - Drupal - 无法从 db_query 获得结果

转载 作者:行者123 更新时间:2023-11-29 00:03:00 25 4
gpt4 key购买 nike

我在 drupal 模块中编写了以下代码。

echo '<pre>';
$data = db_query("SELECT uid, name, status, created, access FROM {users} u WHERE uid <> 0 LIMIT 50 OFFSET 0");
print_r($data);
die;

但它没有给我用户数据,而是给我以下输出:

DatabaseStatementBase Object
(
[dbh] => DatabaseConnection_mysql Object
(
[needsCleanup:protected] =>
[target:protected] => default
[key:protected] => default
[logger:protected] =>
[transactionLayers:protected] => Array
(
)

[driverClasses:protected] => Array
(
[SelectQuery] => SelectQuery
)

[statementClass:protected] => DatabaseStatementBase
[transactionSupport:protected] => 1
[transactionalDDLSupport:protected] =>
[temporaryNameIndex:protected] => 0
[connectionOptions:protected] => Array
(
[database] => aaldev
[username] => root
[password] =>
[host] => localhost
[port] =>
[driver] => mysql
[prefix] => Array
(
[default] =>
)
)

[schema:protected] =>
[prefixes:protected] => Array
(
[default] =>
)

[prefixSearch:protected] => Array
(
[0] => {
[1] => }
)

[prefixReplace:protected] => Array
(
[0] =>
[1] =>
)
)

[queryString] => SELECT uid, name, status, created, access FROM users u WHERE uid <> 0 LIMIT 50 OFFSET 0
)

请帮我解决这个问题。

最佳答案

假设您的查询是正确的,并且Drupal documentation ,你有一个 fetchAll() 方法:

   $data = db_query("SELECT uid, name, status, created, access FROM {users} u WHERE uid <> 0 LIMIT 50 OFFSET 0");
$data->fetchAll();

将所有记录检索到 stdClass 对象的索引数组中。

关于php - Drupal - 无法从 db_query 获得结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28853746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com