我想通过循环绑定n个查询并在单个调用中执行查询。这有可能吗?
foreach($values as $value){
$stmt = $conn->prepare("insert into tablename (val) values (?)");
$stmt->bind_param("i",$val);
}
$stmt->execute();
答案 0 :(得分:0)
示例代码
$valArray = array();
foreach($values as $val)
{
$valArray[] = "($val)";
}
$valString = implode(',', $valArray);
$stmt = $pdo->query("insert into tablename (val) values $valString");