db_insert in Drupal 7 without field names I have the following INSERT in a db_query, but feel like I should convert it to a db_insert, but can't figure out the syntax:

INSERT INTO {mytable} VALUES (23, 'foo', 'bar', 42)


This example is fairly short, but I do work with some legacy tables that have MANY fields.

$insert = db_insert('variables')-&gt;values(array(23, 'foo', 'bar', 42));
$insert-&gt;execute();


The above gives me "NoFieldsException: There are no fields available to insert with. in InsertQuery->preExecute()".

How can you perform an insert with db_insert without needing to specify each field name?
I can make it work in D7 with db_query([INSERT...]); but drupal_write_record does not work.
You can not do this with db_insert().  You could probably dig into the InsertQuery class and get it done, but that's no different than what you're already doing IMO.

I have never seen INSERT without specifying column names, for good reason, although apparently you can (mysql api).  If you do this, it makes it more difficult for someone else to understand what you've done, and impossible to alter the table structure without causing headaches.  

You can look at the waydrupal_write_record() uses drupal_get_schema() to create the fields if you'd like to automate the process (although it would probably take just as long to write the $fields array one time).