PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined: I get "PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined" using the below db_query() call.

db_query("SELECT image.:field1_fid as fid, image.:field2_data as file_data, image.:field3_list AS list FROM {content_:field4} AS image WHERE vid = :vid AND nid = :nid", array(':field1' =&gt; array_values($field), ':field2' =&gt; array_values($field), ':field3' =&gt; array_values($field), ':field4' =&gt; array_values($node_type), ':vid' =&gt; array_values($vid), ':nid' =&gt; array_values($nid)));


I also tried like this.

db_query("SELECT image.:field1_fid as fid, image.:field2_data as file_data, image.:field3_list AS list FROM {content_:field4} AS image WHERE vid = :vid AND nid = :nid", array(':field1' =&gt; $field, ':field2' =&gt; $field, ':field3' =&gt; $field, ':field4' =&gt; $node_type, ':vid' =&gt; $vid, ':nid' =&gt; $nid));


Wny idea what's wrong in my query?
A parameter to a query is something that will go in the WHERE/HAVING clause, it can't be used to substitute text into the SELECT or FROM (or any other part) part of the query. As you've only got two proper parameters in the query (those after the WHERE clause), and you're passing several more as the arguments, you get an error informing you of the count mismatch.

You're also trying to pass in arrays as single string parameter replacements to the SELECT and FROM parts of the query, which will just never work (even if you could use parameter replacement in those part of the query). When cast to a string, the array will simply be the string Array, which is pretty much definitely not what you're looking for.

If you want to build those parts of your query dynamically you'll need to use db_select() instead. This code isn't a complete representation of your example but should get you going:

$query = db_select('content_' . $table_name, 'image');

$query-&gt;addExpression('image.' . $field_name);
$query-&gt;addExpression('image.' . $field2_name);
// etc...

$query-&gt;condition('vid', $vid);

$results = $query-&gt;execute();