【问题标题】:db_select() on Drupal 7 - problem with fieldDrupal 7 上的 db_select() - 字段问题
【发布时间】:2019-03-27 13:44:49
【问题描述】:

下面的代码有问题:

db_select('field_data_commerce_price', 'f')->fields('f', 'commerce_price_amount')->execute()->fetchAssoc()

错误是:“TypeError:传递给 SelectQuery::fields() 的参数 2 必须是数组类型,给定字符串”。请帮忙。

【问题讨论】:

    标签: php database drupal drupal-7


    【解决方案1】:

    出现此错误是因为您在字段方法中将字符串作为参数更改为数组,并且错误将得到解决。执行以下操作

      db_select('field_data_commerce_price', 'f')->fields('f', array('commerce_price_amount') )->execute()->fetchAssoc()
    

    【讨论】:

      【解决方案2】:

      我觉得错误信息很清楚,fields方法的第二个参数必须是数组,这样试试:

      db_select('field_data_commerce_price', 'f')->fields('f', ['commerce_price_amount'])->execute()->fetchAssoc()
      

      【讨论】:

      • 仅限 PHP5.4+
      猜你喜欢
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多