SQLite3: как вставить несколько строк одним запрсом?
Собственно:
public function orderAdd($order)
{
foreach ($order as $val) {
$params = [
'id' => null,
'article' => htmlentities($val['article'], ENT_QUOTES),
'title' => htmlentities($val['title'], ENT_QUOTES),
'order' => '33',
'price' => htmlentities($val['price'], ENT_QUOTES),
'quantity' => htmlentities($val['quantity'], ENT_QUOTES),
];
return $this->db->query('INSERT INTO `orderproducts` VALUES (:id, :article, :title, :order, :quantity, :price)', $params);
}
}
public function query($sql, $params = [])
{
$stmt = $this->db->prepare($sql);
if (!empty($params)) {
foreach ($params as $key => $val) {
if (is_int($val)) {
$type = PDO::PARAM_INT;
} else {
$type = PDO::PARAM_STR;
}
$stmt->bindValue(':' . $key, $val, $type);
}
}
$stmt->execute();
return $stmt;
}