Table prefixes with db_select() in SimpleTest tests How can I do database queries using functions like db_select() and db_query() in my DrupalWebTestCase sub-class? When I try to run them, I get an error:


  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 'simpletest421143 WHERE (nid = '1')' at line 2`


I think it's because the tables aren't properly prefixed, yet I see the prefix in the error string. So it seems that it's trying to prefix, but not doing it properly. 

How can I use these functions in my testing class?
Executing queries inside SimpleTest tests is not different from executing them in a module. The path.test file contains the following code, and it is executed without errors.

$forum_vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module = 'forum'")-&gt;fetchField();
$tid = db_insert('taxonomy_term_data')
  -&gt;fields(array(
    'name' =&gt; $this-&gt;randomName(),
    'vid' =&gt; $forum_vid,
  ))
  -&gt;execute();