【发布时间】:2010-09-08 22:51:40
【问题描述】:
drupal 有没有像drupal_write_record 这样的简单阅读版本。我想从名为{allcategories} 的表中读取一条记录,并找到具有值computers 的category 字段的记录。这是一个使用模式定义的自定义表。
【问题讨论】:
标签: php database drupal drupal-6
drupal 有没有像drupal_write_record 这样的简单阅读版本。我想从名为{allcategories} 的表中读取一条记录,并找到具有值computers 的category 字段的记录。这是一个使用模式定义的自定义表。
【问题讨论】:
标签: php database drupal drupal-6
Drupal 6 中并不真正存在您要查找的内容。drupal_write_record just barely made it into Drupal 6。在 Drupal 7 中,数据库 API 本身使这变得非常简单,以至于我不希望有另一个抽象层,例如“drupal_read_record”:
$record = db_select('allcategories') // table
->condition('category', 'computers') // field & value
->execute() // do it
->fetch(); // get the result
【讨论】:
$result = db_query('SELECT a.* FROM {allcategories} a WHERE a.category="%s"', 'computers');
while ($row = db_fetch_object($result)) {
print $row->[YOURCOLUMNNAME].'<br/>';
// other actions...
}
【讨论】:
db_query。我希望有drupal_read_record 或类似的东西。
据我所知,drupal 不支持 ORM。开发状态下确实存在一个贡献的 ORM 模块 http://drupal.org/project/orm/
【讨论】: