db_select() 在 Drupal 7 上 - 字段问题

db_select() on Drupal 7 - problem with field

我对以下代码有疑问:

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

错误是:"TypeError: Argument 2 passed to SelectQuery::fields() must be of the type array, string given"。请帮忙

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

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

出现此错误是因为您在字段方法中将字符串作为参数更改为数组,错误将得到解决。做如下的事情

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