PDO Prepared Inserts multiple rows in single query

后端 未结 22 2095
感情败类
感情败类 2020-11-21 23:38

I am currently using this type of SQL on MySQL to insert multiple rows of values in one single query:

INSERT INTO `tbl` (`key1`,`key2`) VALUES (\'r1v1\',\'r1         


        
22条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 00:07

    Here is my simple approach.

        $values = array();
        foreach($workouts_id as $value){
          $_value = "(".$value.",".$plan_id.")";
          array_push($values,$_value);
        }
        $values_ = implode(",",$values);
    
        $sql = "INSERT INTO plan_days(id,name) VALUES" . $values_."";
        $stmt = $this->conn->prepare($sql);
        $stmt->execute();
    

提交回复
热议问题