Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bulk insert in zend framework [duplicate]

Possible Duplicate:
How do I add more than one row with Zend_Db?

everyone,

I need to have a bulk insert in zend framework. For normal sql I have the below query, I want to do the same in zend framework.

INSERT INTO `dbname`.'tablename` (`id`, `user_id`, `screen_name`, `screen_name_server`) VALUES (NULL, '15', 'test', 'test'), (NULL, '15', 'test', 'test');

Thanks.

like image 693
anurodh Avatar asked Jul 22 '11 11:07

anurodh


2 Answers

There's no way to do this, as Marcin states.

If you'd like to do some messing around with the Zend Framework you'd could try to alter the insert.

You could try to make it so that the insert method can take an array of arrays for the data. Then you could use the arrays of data to build the bulk insert.

For example,



$data1 = array( ); //data for first insert

$data2 = array( ); //data for 2nd insert

//a zend_db_table object

$dbTable->insert( array( $data1, $data, ) );


You would have to edit the insert method a bit to detect multiple data inserts and then build the insert accordingly. Unfortunately I haven't looked into how the code is built or I would just put it up here for you to use.

like image 182
Jerry Saravia Avatar answered Oct 18 '22 01:10

Jerry Saravia


There is no insert method in zend_db that would insert multiple rows. What you can do though, is to use query method of Zend_Db_Adapter and put there your own insert sql.

like image 40
Marcin Avatar answered Oct 18 '22 00:10

Marcin