Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Array - Array-Werte in die MySQL-Tabelle einfügen

Versuchen Sie es mit einer for each-Schleife anstelle von while

data[0][firstName]  James
data[0][lastName]   Smith
data[1][firstName]  Jane
data[1][lastName]   Doe
data[2][firstName]  Bob 
data[2][lastName]   Builder
etc..

foreach($data as $d){
    $person_fname = $d['firstName'];
    $person_lname = $d['lastName'];

    $query_init2 = "INSERT INTO person ( first_name, last_name) VALUES (:person_fname,:person_lname);";
    $query_prep2 = $db_con->prepare($query_init2);
    $insert_result2 = $query_prep2->execute(array(
      "person_fname" => $person_fname,
      "person_lname" => $person_lname
    ));
}