how to build multiple insert query in zend framework [duplicate]
Asked Answered
L

2

7

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

i would like to build this query

INSERT INTO ad-page (ad_name, page_name) VALUES ('value1', 'value2'), ('value3', 'value4') , ....

i tried this which did not work

        $adpagemodel = new Admin_Model_AdPage();

        if(count($adpage)> 0)
            foreach($adpage as $page)
            {
                $newdatap[]['page_name'] = $page;
                $newdata[]['ad_name'] = $adname;            
            }
        $adpagemodel->insert($newdata); 

and please also check this

Lennyleno answered 26/1, 2011 at 8:53 Comment(0)
H
22

There is simple option. Create the query by hand ;)

like this:

$query = 'INSERT INTO ' . $db->quoteIdentifier('table') . ' (`col1`, `col2`) VALUES ';
$queryVals = array();
foreach ($data as $row) {
    foreach($row as &$col) {
        $col = $db->quote($col);
    }
    $queryVals[] = '(' . implode(',', $row) . ')';
}
$stmt = $db->query($query . implode(',', $queryVals));
Hemicrania answered 17/3, 2011 at 12:47 Comment(0)
A
2

Not all databases support this. So, there is no universal answer. But if you would tell what's you DB, we might suggest some trick... :-)

Amalekite answered 26/1, 2011 at 9:0 Comment(1)
mysql supports this, but the problem is i don't know how to create this statement through dbmodel, instead i have to iterate through loop and insert multiple valuesLennyleno

© 2022 - 2024 — McMap. All rights reserved.