Drupal - 无法从 db_query 获得结果
Drupal - Unable to get result from db_query
我在 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 对象的索引数组中。
我在 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 对象的索引数组中。