简体   繁体   English

如何在 Drupal 7 中获取特定列

[英]How to fetch specific column in Drupal 7

I am trying to fetch one column which is (filename) in my table.我试图在我的表中获取一列(文件名)。

Below is my query:以下是我的查询:

$query = db_select('network_drive_listing','n');
$query
    ->fields('n', array('filename'))
  ->condition('n.network_drive_id',$id)
  ->condition('n.is_dir',0)
  ->orderBy('n.ndlistid');
    $results = $query->execute();

echo "<pre>".print_r($results)."</pre>"; die;

and my output looks like below:我的输出如下所示:

             DatabaseStatementBase Object ( [dbh] => DatabaseConnection_mysql Object ( [needsCleanup:protected] => [target:protected] => default [key:protected] => default [logger:protected] => [transactionLayers:protected] => Array ( ) [driverClasses:protected] => Array ( [SelectQuery] => SelectQuery [InsertQuery] => InsertQuery_mysql [DatabaseSchema] => DatabaseSchema_mysql ) [statementClass:protected] => DatabaseStatementBase [transactionSupport:protected] => 1 [

I am trying to get one specific column, what am I doing wrong?我正在尝试获取一个特定的列,我做错了什么?

You need to call a fetch method onto your result object.您需要对结果对象调用 fetch 方法。 Ie.: IE。:

$results = $query->execute()->fetchField();

Please have a read on these too:请阅读以下内容:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM