0
$columns = "'".implode("','", array_keys($result_1[0]))."'";
  $values = "`".implode("`,`", array_values($result_1[0]))."`";

  $stmt_2 = $db->prepare("INSERT INTO orders ($columns) VALUES ($values)"); try{
    foreach($result_1 as $a){
      $stmt_2->execute(($a));
    }
    var_dump($stmt_2);
  }catch(Exception $e){
    var_dump($e);
  }

The query output is:

INSERT INTO orders ('product_id','quantity','user_id','created','modified',
        'address','phone','email') 
    VALUES (`1`,`1`,`f0df07b5434d46ab9df6295c1c265913106a6f33`,`2020-01-04 06:08:43`,`2020-01-04 10:53:43`,
        `LA`,`9898989898`,`rabc@mail.com)
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55

0 Answers0