views:

1771

answers:

2

I have an array with information which looks more or less like this:

$data[] = array('content'=>'asd');
$data[] = array('content'=>'asdf');

And I want to add both entries into the Database.

$db->insert('table', $data);

does not add both entries. What am I doing wrong? Do I have to use Zend_ Db_Table?

$data = array('content'=>'asdf');
$db->insert('table', $data);

works of course

+7  A: 
tharkun
This is not true: $sql = "INSERT INTO beautiful (name, age) VALUES ('Helen', 24), ('Katrina', 21)"; works (just an example)
Thomaschaaf
you're right. I still don't think zf supports it and there is no hint to it anywhere in the manual. but i'm not sure.
tharkun
LOL! I wish I had gotten the opportunity for upvotes for that! Well done Tharkun, for finding and reposting that.
Bill Karwin
yeah guys, vote me up and Bill will know, his old text is still as good as ever! ;)
tharkun
/me Embarrassed at using a pretentious word like "tuple" instead of simply "row."
Bill Karwin
+11  A: 

You can execute any SQL syntax you want -- including multi-row INSERT statements -- via the Zend_Db_Adapter_Abstract::query() method.

But methods of the Zend_Db_Table and Zend_Db_Table_Rowset classes don't have any support for inserting multiple rows in one go.

Bill Karwin
corect. but insertMultiple() will be useful and much easier...
Elzo Valugi