Fixes for PDO MySQL driver, plus fixes for SQLite queries.

Miscellaneous bugfixes from pdo migration in MySQL codepaths.

Also fixes for SQLite, which stumbles on multiple VALUES in INSERTs.