我的数组像这样显示,但我似乎无法将它保存到数据库中。因此,当我var_dump($result);
在 $result 是我的数组时这样做时,会显示以下内容
array
0 =>
array
'Credit Weighting' => string '5' (length=1)
'Teaching Period(s)' => string 'Teaching Periods 1 and 2.' (length=25)
'No. of Students' => string '-.' (length=2)
1 =>
array
'Credit Weighting' => string '5' (length=1)
'Teaching Period(s)' => string 'Teaching Periods 1 and 2.' (length=25)
'No. of Students' => string '-.' (length=2)
2 =>
array
'Credit Weighting' => string '10' (length=2)
'Teaching Period(s)' => string 'Teaching Periods 1 and 2.' (length=25)
'No. of Students' => string '-.' (length=2)
下面是我的 PDO 查询,用于将上述内容保存到 mysql 中,但没有发生任何事情。请问我做错了什么?
$result = array();
$placeholder = array();
$values = "?, ?, ?";
foreach ($result as $array){
$placeholder[] = $value;
$result[] = $array['CreditWeighting'];
$result[] = $array['TeachingPeriod'];
$result[] = $array['NoofStudents'];
}
$sql = "INSERT INTO data_array_copy (CreditWeighting,TeachingPeriod,NoofStudents)
VALUES (". implode('), (', $placeholder) . ")";
$stmt = $conn->prepare($sql);
$stmt->execute($result);