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

问题描述 投票:0回答:2

我有以下代码的问题:

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

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

php database drupal drupal-7
2个回答
1
投票

此错误即将发生,因为您在字段方法中将字符串作为参数更改为数组,并且将解决错误。做类似下面的事情

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

1
投票

我认为错误信息非常清楚,fields方法的第二个参数必须是数组,请尝试这种方式:

db_select('field_data_commerce_price', 'f')->fields('f', ['commerce_price_amount'])->execute()->fetchAssoc()
© www.soinside.com 2019 - 2024. All rights reserved.