在php-mysql中保存并迭代数组

Bak*_*562 1 html php

我有以下代码在我的数据库中保存数组:

public function agregarBolsasModel($datos, $tabla) {
        $datosL=array($datos["valoresBox"]);
        $stmt = Conexion::conectar() -> prepare("INSERT INTO $tabla(lote, caja, bolsa)VALUES(:one, :two, :three)");

        for($p = 0; $p < sizeof($datosL); $p++) {
            $stmt -> bindParam(":one", $datos["loteNum"], PDO::PARAM_INT);
            $stmt -> bindParam(":two", $datos["cajaNum"], PDO::PARAM_INT);
            $stmt -> bindParam(":three", $datosL[$p], PDO::PARAM_INT);
            $stmt->execute();
        }

        $stmt->close();
}
Run Code Online (Sandbox Code Playgroud)

three是一个数组[1,2,3],我不知道它的大小因为它是dinamyc数组,但我无法将数据保存在我的数据库中,当我尝试保存数据时收到以下错误:

public function agregarBolsasModel($datos, $tabla) {
        $datosL=array($datos["valoresBox"]);
        $stmt = Conexion::conectar() -> prepare("INSERT INTO $tabla(lote, caja, bolsa)VALUES(:one, :two, :three)");

        for($p = 0; $p < sizeof($datosL); $p++) {
            $stmt -> bindParam(":one", $datos["loteNum"], PDO::PARAM_INT);
            $stmt -> bindParam(":two", $datos["cajaNum"], PDO::PARAM_INT);
            $stmt -> bindParam(":three", $datosL[$p], PDO::PARAM_INT);
            $stmt->execute();
        }

        $stmt->close();
}
Run Code Online (Sandbox Code Playgroud)

我的错是什么?我该怎么做才能解决这个问题?

感谢名单

小智 5

PDO没有"关闭"功能.你可以做

$ this-> db = null;

在你的情况下,在$ stmt