views:

46

answers:

3

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.

+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
+1 but I know about `db_query`. I was hoping there was `drupal_read_record` or something like that.
jblue
ah, forgot to say about this, wait for drupal 7 :)
Nikit
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
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
+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