http://drupal.org/node/82963

More specificially..

<?php
$query = "SELECT nid, title, created FROM " .
         "{node} WHERE created >= '" . $start_time .
         "' AND created <= '". $end_time . "'";
?>

What I don't understand is this {node} business. I understand that you need it so that it can attach your table prefix but could someone explain to me how it selects the table name. If I wanted to gather information from the members database instead, how would I do that?

Comments

nancydru’s picture

"Node" IS the table name (which will be prefixed if necessary). The "FROM" verb tells SQL that the following information is the table name. Since Drupal works with several different databases, we use the brackets to enclose it (BTW, they are not always needed, but it's safer to use them); standard MySql would use back ticks (`).

The "members" table, is, I assume from your question, the users tables.

Might I suggest that you search on the web for a tutorial on MySql?

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

cog.rusty’s picture

I am not sure I understand the question. What is the members database, an external one? Do you mean something like this?

How to connect to multiple databases within Drupal
http://drupal.org/node/18429
http://api.drupal.org/api/5/function/db_set_active

If you are asking something else, take a look here

http://api.drupal.org/api/5/group/database
http://api.drupal.org/api/5/function/db_prefix_tables

xjm’s picture

I believe {node} references a global constant for the name of the node table. This insulates Drupal's code from the actual names of database tables, so if the node table is ever something besides "node" it will still work. node is the name of the constant, and the {} tell PHP to evaluate node as such within the string.

You can show a list of all the tables in your database with the query
show tables;
and you can find out what fields a particular table has with
describe `my_table`;
(quickest on a mysql command line).

For the "members" table, if you mean members of the site, you probably want {user}.

nevets’s picture

The use of {table_name} is simply to support table prefixes. db_query preprocesses the sql prepending the prefix (if there is one) to any thing surrounded by '{' and '}'