i am currently running into an issue were i want to insert an array with prepared statements by pdo to my databse. I found some code here to start with, but currently its only inserting one of the files in the array $files which is passed to that method.
$amount = count($files);
for($i=0; $i<$amount; $i++){
$dbArr=[
'path' => (string) dirname( $files[$i] ),
'name' => (string) basename( $files[$i] ),
'size' => (int) filesize($files[$i]),
'mimeType' => (string) mime_content_type( $files[$i] ),
];
}
foreach($dbArr as $k => $v ) {
$prep[':'.$k] = $v;
}
new sql();
$q = sql::$db->prepare($str = "INSERT INTO filesSrc ( " . implode(', ',array_keys($dbArr)) . ") VALUES (" . implode(', ',array_keys($prep)) . ")");
$res = $q->execute($prep);
It works, but only inserts one of the array. the solution might be simple, i am overlooking something.