What is the best way to insert multiple rows in single query using PHP prepared statements?
I have this multidimensional data:
$data = array(
'6' => array(
'945' => array(
'11:04' => array(
'0' => array(
'date' => '2013-02-02',
'user' => '3'
),
),
'11:05' => array(
'0' => array(
'date' => '2013-02-03',
'user' => '3'
),
),
'11:06' => array(
'0' => array(
'date' => '2013-02-03',
'user' => '3'
),
)
)
);
And the query I used is :
$ins = $this->conn->prepare("INSERT INTO table (date, user) VALUES ('2013-02-03', '03' )");
$ins->execute();
The query above is working but it just insert only one row so I tried to used the foreach as below:
foreach ($data as $dk => $dv) {
foreach ($dv as $k => $v) {
foreach ($v as $rk => $rv) {
$ins = $this->conn->prepare("INSERT INTO table (date, user) VALUES ($rv['date'], $rv['user'] )");
$ins->execute();
}
}
}
I want to query as:
INSERT INTO emp (date,user) VALUES("2013-02-02",3),("2013-02-02",3),("2013-02-03",3);
Please help