【发布时间】:2020-03-05 10:30:14
【问题描述】:
我有 3 个数组,我想要实现的是,使用 foreach 循环,我想在数据库中插入多行。 这是我正在尝试的代码。
$array1 = ('Hello First row', 'Hello Second Row', 'Hello third row', 'Hello Forth row');
$array2 = ('This going to be First row', 'This going to be Second Row', 'This going to bethird row', 'This going to beForth row');
$array3 = ('also the first row', 'also the Second Row', 'also the third row', 'also the Forth row');
$stmt = $db->prepare("INSERT INTO table_name(first, second, third) VALUES (:first, :second, :third)");
$stmt->execute(array(':first' => $array1, ':second' => $array2, ':third' => $array3));
PS:我尝试在 $stmt 执行函数上方使用 foreach 循环,但这并没有按预期工作。!它在表中创建了 12 行。假设只有 4 个。
【问题讨论】: