我有以下代码在我的数据库中保存一个数组:
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();
}
three
的值是一个像 [1,2,3]
这样的数组,我不知道它的大小,因为它是一个动态数组,但我可以' t 将数据保存在我的数据库中,当我尝试保存数据时,我也收到以下错误:
Fatal error>: Uncaught error: Call to undefined method PDOStatement::close()
我的错误是什么?我该如何解决这个问题?
谢谢
最佳答案
PDO 没有“关闭”功能。你可以做
$this->db = null;
在你的例子中,在 $stmt
关于php - 在php-mysql中保存并迭代数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48909106/