Hallo, kann mir jemand einen Rat geben, ich versuche gerade PDO Query auszuführen.
Die Tabelle soll so aussehen.
status | array_werte
1 | 1
1 | 2
1 | 3
1 | 4
1 | 5
Mein Code
Hat jemand einen Idee?
Die Tabelle soll so aussehen.
status | array_werte
1 | 1
1 | 2
1 | 3
1 | 4
1 | 5
Mein Code
PHP-Code:
$status = '5';
$array = [1,2,3,4,5];
# Dieses Beispiel funktioniert nicht.
$save_data = "INSERT INTO table (status, array_values) VALUES (:status, :array)";
$stmt->bindParam(':status', $status);
$stmt->bindParam(':array', $array);
return $stmt->execute();
# Dieses Beispiel funktioniert nicht
$save_data = "INSERT INTO table (status, array_values) VALUES (:status, :array)";
foreach($array as $value){
$stmt->bindParam(':status', $status);
$stmt->bindParam(':array', $value);
return $stmt->execute();
}
# Dieses Beispiel funktioniert aber sieht merkwürdig aus.
foreach($array as $value){
$save_data = "INSERT INTO table (status, array_values) VALUES (:status, :array)";
$stmt->bindParam(':status', $status);
$stmt->bindParam(':array', $value);
return $stmt->execute();
}
Kommentar