How to pass a db_query as an array instead of a string? I am having a bit of trouble converting my module db_query argument to pass as an array as oppose to a string. The module is D6 and I am trying to port it D7. Here is the snippet:

$result = db_query("SELECT nfi.field_name, nfi.label
  FROM {field_config_instance()} nfi
    INNER JOIN {field_config()} nf ON nfi.field_name = nf.field_name
  WHERE nfi.type_name = '%s' AND nf.active = 1 AND nf.locked = 0", $type_name);


And here the updated version as suggested below, but I am still getting a PDOException error:

$result = db_query("SELECT nfi.field_name, nfi.label
  FROM {field_config_instance()} nfi
    INNER JOIN {field_config()} nf ON nfi.field_name = nf.field_name
  WHERE nfi.type_name = ':type_name'  AND nf.active = 1 AND nf.locked = 0", array(':type_name'=&gt;$type_name));


The full error is as below, line 49 is the line starting "WHERE" or the entire bottom line basically:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() nfi INNER JOIN field_config() nf ON nfi.field_name = nf.field_name ' at line 2: SELECT nfi.field_name, nfi.label FROM {field_config_instance()} nfi INNER JOIN {field_config()} nf ON nfi.field_name = nf.field_name WHERE nfi.type_name = ':type_name' AND nf.active = 1 AND nf.locked = 0; Array ( [:type_name] => page ) in cck_private_fields_get_content_private_fields() (line 49 of C:|... common.inc).

Any suggestions welcome. When I manage to finish this module I'll be submitting it to Drupal.org so everyone can use it.
There are three errors in that query:


The database tables are not field_config_instance(), and field_config(), but field_config_instance, and field_config. Parentheses have a particular meaning in SQL, and putting them after a table name causes an error message.
The field_config_instance table doesn't contain any "label" field. See the schema definition given in field_schema().

$schema['field_config_instance'] = array(
  'fields' =&gt; array(
    'id' =&gt; array(
      'type' =&gt; 'serial', 
      'not null' =&gt; TRUE, 
      'description' =&gt; 'The primary identifier for a field instance',
    ), 
    'field_id' =&gt; array(
      'type' =&gt; 'int', 
      'not null' =&gt; TRUE, 
      'description' =&gt; 'The identifier of the field attached by this instance',
    ), 
    'field_name' =&gt; array(
      'type' =&gt; 'varchar', 
      'length' =&gt; 32, 
      'not null' =&gt; TRUE, 
      'default' =&gt; '',
    ), 
    'entity_type' =&gt; array(
      'type' =&gt; 'varchar', 
      'length' =&gt; 32, 
      'not null' =&gt; TRUE, 
      'default' =&gt; '',
    ), 
    'bundle' =&gt; array(
      'type' =&gt; 'varchar', 
      'length' =&gt; 128, 
      'not null' =&gt; TRUE, 
      'default' =&gt; '',
    ), 
    'data' =&gt; array(
      'type' =&gt; 'blob', 
      'size' =&gt; 'big', 
      'not null' =&gt; TRUE, 
      'serialize' =&gt; TRUE,
    ), 
    'deleted' =&gt; array(
      'type' =&gt; 'int', 
      'size' =&gt; 'tiny', 
      'not null' =&gt; TRUE, 
      'default' =&gt; 0,
    ),
  ), 
  'primary key' =&gt; array('id'), 
  'indexes' =&gt; array(
    // Used by field_delete_instance().
    'field_name_bundle' =&gt; array('field_name', 'entity_type', 'bundle'),
    // Used by field_read_instances(). 
    'deleted' =&gt; array('deleted'),
  ),
);

Drupal 7 placeholders aren't wrapped between quotes, when they are for strings.


The following query should not return any error.

SELECT nfi.field_name FROM {field_config_instance} nfi
  INNER JOIN {field_config} nf ON nfi.field_name = nf.field_name
  WHERE nfi.type_name = :type_name  AND nf.active = 1 AND nf.locked = 0