"By the book" way" with db_set_active('products'); fails if I have no session active when I press submit. No session table in product schema (of course it's not there). Does db_insert use sessions? It happened to me only thrice in couple of days, but that's not something I'm willing to show to my client. Twice in 7.22, once in 7.x-dev.
I tried to work around it (ab)using target option, but no success either.
<?php
$idBrand = db_insert('brand', array('target'=> 'products'))->fields(
array(
'BrandName'=> $item['name'],
'BrandIcon'=> $item['BrandIcon'],
))->execute();
?>
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal7.brand' doesn't exist: INSERT INTO {brand} (BrandName, BrandIcon) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => AAT [:db_insert_placeholder_1] => 11 )