我尝试插入具有不同值的多行,但我不知道为什么不起作用
$id_poliza = $this->dbConnect->lastInsertId(); //With this, I save last insert id from last executed sql statement.
if($this->dataNewPoliza['d724'] == 'on')
$disp1 = 1;
else
$disp1 = 0;
if($this->dataNewPoliza['d58'] == 'on')
$disp2 = 1;
else
$disp2 = 0;
if(($this->dataNewPoliza['especial']) == '')
$disp3 = 0;
else
$disp3 = $this->dataNewPoliza['especial'];
if(($this->dataNewPoliza['ticket']) == '')
$disp4 = 0;
else
$disp4 = $this->dataNewPoliza['ticket'];
$sqlDispPol = "INSERT INTO disponibilidad_poliza (Id_Poliza, Id_Disponibilidad, Valor)
VALUES (:idP,:idD1,:val1),
(:idP,:idD2,:val2),
(:idP,:idD3,:val3),
(:idP,:idD4,:val4)";
$resultDisp = $this->dbConnect->prepare($sqlDispPol) or die ($sqlDispPol);
$resultDisp->bindParam(':idP',$id_poliza,PDO::PARAM_INT);
$resultDisp->bindParam(':idD1',1,PDO::PARAM_INT);
$resultDisp->bindParam(':val1',$disp1,PDO::PARAM_STR);
$resultDisp->bindParam(':idD2',2,PDO::PARAM_INT);
$resultDisp->bindParam(':val2',$disp2,PDO::PARAM_STR);
$resultDisp->bindParam(':idD3',3,PDO::PARAM_INT);
$resultDisp->bindParam(':val3',$disp3,PDO::PARAM_STR);
$resultDisp->bindParam(':idD4',4,PDO::PARAM_INT);
$resultDisp->bindParam(':val4',$disp4,PDO::PARAM_STR);
if($resultDisp->execute()) {
//more code
}
我想从此表格中保存:
表 disponibilidad_poliza
Id_Poliza Id_Disponibilidad Valor
________________________________________
1 1 1
1 2 0
1 3 especial10
1 4 7
Note: $disp1 and $disp2 are checkboxes, $disp3 and $disp4 are inputs text
也许这种方式是不正确的,我很感激如果你用另一种方式来做到这一点。提前致谢。