What would be recommended way to perform Bulk Insert using zend-db (for PgSQL/MySQL) ?
As I remember that feature was too DB specific so it isn’t planned to be implemented into zend-db component.
Right now many DB/Storage support multi insert, maybe is time for consider again such a feature
IIRC, I’ve pulled the driver from the adapter and used that to prepare statements that do bulk inserts:
$driver = $adapter->getDriver();
$statement = $driver->createStatement($sql);
$result = $statement->execute($parameters);
printf("Inserted %d rows\n", $result->getAffectedRows());
Assuming you use unnamed placeholders for the values, and can dynamically determine how many to add, this can work with standard
INSERT syntax across most databases; as to efficiency, it’s anybody’s guess.
Typically, if I’m doing a bulk insert, I use the database’s facilities, as they’re usually far faster. That’s clearly not possible if the database may vary; that said, you could potentially use a
Makefile to vary based on platform, which could solve the problem as well.