尝试在表格中保存两行:victim
假设输出是这样的:
name | age | gender | address | Journal_id
----------------------------------------------------------------
robert | 23 | M | st. lucas calabanga | 1
vender | 25 | M | st. lucas calabanga | 1
我在这里写了一个带有多个绑定参数的准备语句:
$j_id = mysqli_insert_id($this->db);
$stmt = $this->db->prepare("INSERT INTO victim (name, age, gender, address, journal_id) VALUES (?, ?, ?, ?, ?)");
$length = count($vName);
for ($i = 0; $i < $length; $i++)
{
if ($stmt->bind_param('sissi', $vName[$i], $vAge[$i], $vGender[$i], $vAddr[$i], $j_id))
if($stmt->execute())
echo "working";
else
echo "not working";
}
当我运行该代码时,它在我的数据库中没有惰性。任何能帮助我的人。
答案 0 :(得分:0)
for ($i = 0; $i < $length; $i++) {
if($stmt->execute(array($vName[$i], $vAge[$i], $vGender[$i], $vAddr[$i], $j_id))) {
echo "working";
}
else {
echo "not working";
}
}