beginTransaction(); $stmt = $pdo->prepare('Select * from cidit_fd_fechaetapas(:concurso, NULL)'); $stmt->bindParam(':concurso', $concurso); if(!$stmt->execute()){ $return["error"] = "Error al borrar las fechas del concurso"; $error = true; }else{ $stmt->closeCursor(); $stmt = null; //recorre objeto json foreach($clase as $etapa){ if(!$error){//si no hay errores $orden = 1; foreach($etapa["fechas"] as $fecha_row){//recorre listado de fechas if(count($fecha_row) > 0){ $fechas_str = implode(",", $fecha_row);//obiene fechas (inicial, final) y convierte en texto $stmt = $pdo->prepare('Select * from cidit_fi_fechaetapas(:concurso, :etapa, :fechas, :orden)'); $stmt->bindParam(':concurso', $concurso); $stmt->bindParam(':etapa', $etapa["id"]); $stmt->bindParam(':fechas', $fechas_str); $stmt->bindParam(':orden', $orden); if(!$stmt->execute()){ //$t = $stmt->errorInfo(); $return["error"] = "Error al insertar las fechas del concurso.";//.$t[2]; $error = true; break; } } $orden++; $stmt->closeCursor(); } } } } $stmt->closeCursor(); $stmt = null; if(!$error){ $pdo->commit(); $return["ok"]= "Las fechas se actualizaron correctamente"; }else{ $pdo->rollBack(); } } catch(PDOException $e) { $pdo->rollBack(); $return["error"] = "Error al insertar las fechas del concurso.";//.$e->getMessage(); } } $return["json"] = json_encode($return); echo json_encode($return); ?>