How to set new AUTO_INCREMENT value? I have the following statement in my module code:

db_query("ALTER TABLE {tripletex_invoice} AUTO_INCREMENT = :number", array(':number' =&gt; $start_value));


During SimpleTest I get the following error message:

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 ''20000'' at
line 1: ALTER TABLE {tripletex_invoice} AUTO_INCREMENT = :value; Array ( 
[:value] =&gt; 20000 ) in _tripletex_add_invoice_log() (line 1769 of 
/var/www/d7/sites/all/modules/tripletex/tripletex.module).


Why?
Parameter replacement only works for WHERE clauses, it won't work for the kind of query you're trying to run.

You need to insert $start_value directly into the query string. If that value comes from an un-trustworthy source then obviously you need to sanitise it and make sure it falls within the correct bounds yourself:

$start_value = (int)$start_value; // Make sure it's an integer

// Do any other checks you need to here (bounds checking, etc.)

// Build the query string and run it
$sql = "ALTER TABLE {tripletex_invoice} AUTO_INCREMENT = $start_value";
db_query($sql);