Does drupal have a simple version for reading like drupal_write_record
. I want to read a record from a table called {allcategories}
and find the record that has a category
field of value computers
. It's a custom table defined with schema.
views:
46answers:
3
+2
A:
$result = db_query('SELECT a.* FROM {allcategories} a WHERE a.category="%s"', 'computers');
while ($row = db_fecth_object($result)) {
print $row->[YOURCOLUMNNAME].'<br/>';
//... other actions
}
Nikit
2010-09-08 23:23:04
+1 but I know about `db_query`. I was hoping there was `drupal_read_record` or something like that.
jblue
2010-09-08 23:37:26
ah, forgot to say about this, wait for drupal 7 :)
Nikit
2010-09-09 07:46:29
A:
As far as I know, drupal does not have ORM support. A contirbuted ORM module does exists in development state http://drupal.org/project/orm/
brian_d
2010-09-08 23:43:15
The ORM module clearly indicates it's for nodes only, and the question clearly indicates it's not dealing with nodes, so this answer isn't very useful.
Scott Reynen
2010-09-09 00:13:46
+2
A:
What you're looking for doesn't really exist in Drupal 6. drupal_write_record just barely made it into Drupal 6. In Drupal 7, the database API itself makes this straightforward enough that I wouldn't expect another abstraction layer like "drupal_read_record":
$record = db_select('allcategories') // table
->condition('category', 'computers') // field & value
->execute() // do it
->fetch(); // get the result
Scott Reynen
2010-09-09 01:01:38