ZF-2322: Multiple Inserts / Updates from rowsets


Currently, the Zend_DB way to bulk insert (to my knowledge):

$tb = new Table;

for ($i = 0; $i < 500; $i++) { $row = $tb->createRow(); $row->blah = 'blah'; $row->save(); }

// I propose something like this

$count = 5; // count of rows $tb = new Table;

$rowset = $tb->createRowSet($count); $rowset->save();

/** To update **/

$tb = new Table; $rowset = $tb->fetchAll($condition);

// Modify $rowset

$rowset->save(); // This will be saved for rows where $condition is met


Please categorize/fix as needed.

This issue has gone unaddressed for too long. I'm reassigning this to Ralph for re-evaluation and categorization.

Rather than making it too big of a problem - what if we simply added some functionality to Zend_Db_Adapter ?

So given an array of hash :

$db->insert('tablename', $data); // (or multipleInsert or bulkInsert, what have you)

If/when this should get fixed ... it'd be nice to have bulk insert-or-update functionality, too, i.e., INSERT INTO... ON DUPLICATE KEY UPDATE.

Patch that allows support for bulk inserts for MySQL PDO adapter.

The patch supplied has the same method name defined twice. Also, this seems to be heavily MySQL specific and the usage is not portable across database vendors. Shouldn't this be done in userspace since the application is taking advantage of database specific functionality?

My mistake, the second method should have been named "insertOrUpdateMultiple". It takes advantage of MySQL's ON DUPLICATE KEY UPDATE feature.

The patch is for the MySQL PDO adapter -- other adapters would need to implement their own versions of these methods, even if that means looping through the data and performing separate inserts.

Adding new methods to the adapters that other classes (like Zend_Db_Table) would rely on means we may need to update the Zend_Db_Adapter_Abstract. Maybe we can add a simple cross-database version of this that other adapters can override with their own version.