function listarEmpresas() { $CONEXION = new ConexionBD(); $CONEXION->setAtributos(HOST, USER, PASS, BD); $_empresa = $CONEXION->ejecutarConsulta("SELECT DISTINCT nombreEmpresa FROM empresa"); for ($i = 0; $i < count($_empresa["nombreEmpresa"]); $i++) { print "<option value='" . $_empresa["nombreEmpresa"][$i] . "'>" . $_empresa["nombreEmpresa"][$i] . "</option>"; } }
private function insertaDB($listacalles) { $comando = "INSERT INTO " . self::NOMBRE_TABLA . " (" . self::IDCALLE . ", " . self::NOMCALLE . ")" . " VALUES (?,?)"; $pdo = ConexionBD::obtenerInstancia()->obtenerBD(); $sentencia = $pdo->prepare($comando); ini_set('max_execution_time', 300); for ($i = 0; $i < count($listacalles) - 1; $i++) { $calle = $listacalles[$i]; $id = $calle["idCalle"]; $nombre = $calle["nombre"]; $sentencia->bindParam(1, $id, PDO::PARAM_INT); $sentencia->bindParam(2, $nombre); $resultado = $sentencia->execute(); } return $resultado; }
private function obtenerTodosLosPuntos() { try { $comando = "SELECT *" . " FROM " . self::NOMBRE_TABLA; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ejecutar sentencia preparada if ($sentencia->execute()) { $puntos = $sentencia->fetchAll(PDO::FETCH_ASSOC); http_response_code(200); return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de puntos exitosa", "puntos" => $puntos]; } else { throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error"); } } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
public static function obtenerComentariosFestival($idFestival) { try { $comando = "SELECT c." . self::ID_COMENTARIO . " as idComentario" . ", u." . usuarios::NOMBRE . " as nombreAutor" . ", u." . usuarios::CORREO . " as correoAutor" . ", c." . self::ID_FESTIVAL . " as idFestival" . ", c." . self::FECHA . ", c." . self::TEXTO . " FROM " . self::NOMBRE_TABLA . " c" . " INNER JOIN " . usuarios::NOMBRE_TABLA . " u" . " ON c." . self::ID_USUARIO . " = u." . usuarios::ID_USUARIO . " WHERE c." . self::ID_FESTIVAL . " =?" . " ORDER BY " . self::FECHA . " DESC"; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ligar idContenedor $sentencia->bindParam(1, $idFestival, PDO::PARAM_INT); // Ejecutar sentencia preparada if ($sentencia->execute()) { http_response_code(200); return $sentencia->fetchAll(PDO::FETCH_ASSOC); } else { throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error"); } } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
private function obtenerComentarios($idContenedor, $tipo) { try { $comando = "SELECT c." . self::ID_COMENTARIO . " as idComentario" . ", u." . usuarios::NOMBRE . " as nombreAutor" . ", u." . usuarios::IMAGEN . " as encodedImg" . ", c." . self::FECHA . " as fecha" . ", c." . self::TEXTO . " as cuerpo" . " FROM " . self::NOMBRE_TABLA . " c" . " INNER JOIN " . usuarios::NOMBRE_TABLA . " u" . " ON c." . self::ID_USUARIO . " = u." . usuarios::ID_USUARIO . " WHERE " . self::ID_CONTENEDOR . "=? AND " . self::TIPO . "=?" . " ORDER BY " . self::FECHA . " DESC"; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ligar idContenedor $sentencia->bindParam(1, $idContenedor, PDO::PARAM_INT); $sentencia->bindParam(2, $tipo, PDO::PARAM_INT); // Ejecutar sentencia preparada if ($sentencia->execute()) { http_response_code(200); return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de comentarios exitosa", "comentarios" => $sentencia->fetchAll(PDO::FETCH_ASSOC)]; } else { throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error"); } } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
private function obtenerFestivalInfo($id) { $resultado = array(); try { $comando = "SELECT " . self::ID_FESTIVAL . " as idFestival" . ", " . self::NOMBRE_FESTIVAL . " as nombreFestival" . ", " . self::UBICACION_FESTIVAL . " as ubicacionFestival" . ", " . self::LATITUD_FESTIVAL . " as latitudFestival" . ", " . self::LONGITUD_FESTIVAL . " as longitudFestival" . ", " . self::LOGO_URL . " as logoUrl" . ", " . self::BACK_URL . " as backUrl" . ", " . self::DESCRIPCION_FESTIVAL . " as descripcionFestival" . ", " . self::FACEBOOK_URL . " as facebookUrlFestival" . ", " . self::WEB_URL . " as webUrlFestival" . ", " . self::INSTAGRAM_USER . " as instagramUserFestival" . ", " . self::ENTRADAS_URL . " as entradasUrl" . ", " . self::FECHA_INICIO . " as fechaInicio" . ", " . self::FECHA_FIN . " as fechaFin" . ", " . self::ASISTENTES_FESTIVAL . " as asistentesFestival" . ", " . self::EDICIONES_FESTIVAL . " as edicionesFestival" . " FROM " . self::NOMBRE_TABLA . " WHERE " . self::ID_FESTIVAL . "=? ;"; $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $id, PDO::PARAM_INT); if ($sentencia->execute()) { $festival = $sentencia->fetchAll(PDO::FETCH_ASSOC); $artistas = artistas::getArtistaFromFestival($id); $comentarios = comentarios::obtenerComentariosFestival($id); http_response_code(200); return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de festivales exitosa", "festivales" => ["info" => $festival, "artistas" => $artistas, "comentarios" => $comentarios]]; } else { throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error"); } } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
private function crear($alerta) { if ($alerta) { try { $tipo = $alerta->tipo; $descripcion = $alerta->descripcion; $idContenedor = $alerta->idContenedor; $tipoContenedor = $alerta->tipoContenedor; $dirContenedor = $alerta->dirContenedor; $lat = $alerta->lat; $lon = $alerta->lon; $email = $alerta->email; $imagen = $alerta->encodedImg; $fecha = date("Y-m-d H:i:s"); $pdo = ConexionBD::obtenerInstancia()->obtenerBD(); // Sentencia INSERT $comando = "INSERT INTO " . self::NOMBRE_TABLA . " ( " . self::TIPO . "," . self::DESCRIPCION . "," . self::FECHA . "," . self::ID_CONTENEDOR . "," . self::TIPO_CONTENEDOR . "," . self::DIRECCION_CONTENEDOR . "," . self::LATITUD_CONTENEDOR . "," . self::LONGITUD_CONTENEDOR . "," . self::EMAIL_USUARIO . "," . self::IMAGEN . ")" . " VALUES(?,?,?,?,?,?,?,?,?,?)"; // Preparar la sentencia $sentencia = $pdo->prepare($comando); $sentencia->bindParam(1, $tipo); $sentencia->bindParam(2, $descripcion); $sentencia->bindParam(3, $fecha); $sentencia->bindParam(4, $idContenedor, PDO::PARAM_INT); $sentencia->bindParam(5, $tipoContenedor, PDO::PARAM_INT); $sentencia->bindParam(6, $dirContenedor); $sentencia->bindParam(7, $lat); $sentencia->bindParam(8, $lon); $sentencia->bindParam(9, $email); $sentencia->bindParam(10, $imagen); $sentencia->execute(); // Retornar en el último id insertado return $pdo->lastInsertId(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } } else { throw new ExcepcionApi(self::ESTADO_PARAMETROS_INCORRECTOS, utf8_encode("Error en existencia o sintaxis de parámetros")); } }
public static function obtenerSeguidos($idSig) { try { $comando = "SELECT Us.nomUsuario,Us.imgPerfil,Us.idUsuario,Us.numLikes,Us.idUsuario,Us.numRutas FROM " . self::NOMBRE_TABLA . " as seg" . " INNER JOIN Usuario as Us ON Us.idUsuario = seg." . self::ID_SEGUIDO . " WHERE " . self::ID_USUARIO . "=?"; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ligar idUsuario $sentencia->bindParam(1, $idSig, PDO::PARAM_INT); // Ejecutar sentencia preparada if ($sentencia->execute()) { $sig = $sentencia->fetchAll(PDO::FETCH_ASSOC); return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de usuarios a los que sigues exitosa", "siguiendo" => $sig]; } return array(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
<?php /*============================================================================================= CARGA CONEXION BD ==============================================================================================*/ include 'ConexionBD.php'; $config = new ConexionBD(); $db = $config->conectar(); //$db->setFetchMode(DB_FETCHMODE_ASSOC); /*============================================================================================= FUNCTION formatoFechaBD: formatea fecha para la Base de datos ==============================================================================================*/ function formatoFechaBD($fecha) { $salida = ''; if ($fecha != '') { $fecha = str_replace('/', '-', $fecha); $fechaarray = date_parse($fecha); $salida = date('Y-m-d', mktime(0, 0, 0, $fechaarray['month'], $fechaarray['day'], $fechaarray['year'])); } return $salida; } /*============================================================================================= FUNCTION formatoFechaDMY: formatea fecha para la Base de datos ==============================================================================================*/ function formatoFechaDMY($fecha) { $salida = ''; if ($fecha != '') { $fecha = str_replace('/', '-', $fecha); $fechaarray = date_parse($fecha);
<?php require '../conexion/conexion.php'; session_start(); if (isset($_POST['Entrar'])) { $conn = new ConexionBD(); $link = $conn->conectarBD(); $user = $_POST['usuario']; $pass = $_POST['contrasenia']; $query = "call sp_validarLogin('{$user}','{$pass}')"; $result = mysqli_query($link, $query); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); if ($row[0] == "N") { header("Location: ../login.php?errn=1"); } else { if ($row[0] == "B") { header("Location: ../login.php?errb=1"); } else { if ($row[0] == "I") { header("Location: ../login.php?erri=1"); } else { $_SESSION['Administrador'] = $row[0] . $row[1]; header("Location: ../index.php"); } } } } else { header("Location: ../login.php?"); } mysqli_close($link);
private function crear($idUsuario, $reciclaje) { if ($reciclaje) { try { $tipo = $reciclaje->tipo; $fecha = date("Y-m-d H:i:s"); $peso = self::calculaPeso($tipo); $pdo = ConexionBD::obtenerInstancia()->obtenerBD(); // Sentencia INSERT $comando = "INSERT INTO " . self::NOMBRE_TABLA . " ( " . self::TIPO . "," . self::PESO . "," . self::FECHA . "," . self::ID_USUARIO . ")" . " VALUES(?,?,?,?)"; // Preparar la sentencia $sentencia = $pdo->prepare($comando); $sentencia->bindParam(1, $tipo, PDO::PARAM_INT); $sentencia->bindParam(2, $peso); $sentencia->bindParam(3, $fecha); $sentencia->bindParam(4, $idUsuario); $sentencia->execute(); $idReciclaje = $pdo->lastInsertId(); return $idReciclaje; } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } } else { throw new ExcepcionApi(self::ESTADO_PARAMETROS_INCORRECTOS, utf8_encode("Error en existencia o sintaxis de parámetros")); } }
function _destructor() { self::$pdo = null; }
public static function obtenerRutasFav($idUsuRutFav) { try { $comando = "SELECT ru.idRuta,ru.nomRuta,ru.valoracion,ru.idCategoriaRut, ru.idUsuario_ruta FROM " . self::NOMBRE_TABLA . " AS fav" . " INNER JOIN Ruta AS ru ON ru.idRuta = fav." . self::ID_RUTA . " WHERE " . self::ID_USUARIO . "=?"; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ligar idUsuario $sentencia->bindParam(1, $idUsuRutFav, PDO::PARAM_INT); // Ejecutar sentencia preparada if ($sentencia->execute()) { $ruta = $sentencia->fetchAll(PDO::FETCH_ASSOC); return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de rutas favorita exitosa", "rutas" => $ruta]; } return array(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
private function obtenerFavoritos($idUsuario) { try { $comando = "SELECT " . self::ID_FAVORITO . " as idFavorito" . ", " . self::ID_CONTENEDOR . " as idContenedor" . ", " . self::TIPO . " as tipo" . ", " . self::DIRECCION . " as direccion" . ", " . self::LATITUD . " as lat" . ", " . self::LONGITUD . " as lon" . " FROM " . self::NOMBRE_TABLA . " WHERE " . self::ID_USUARIO . "=?"; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ligar idUsuario $sentencia->bindParam(1, $idUsuario, PDO::PARAM_INT); // Ejecutar sentencia preparada if ($sentencia->execute()) { http_response_code(200); return ["estado" => self::ESTADO_EXITO, "mensaje" => "Consulta de favoritos exitosa", "favoritos" => $sentencia->fetchAll(PDO::FETCH_ASSOC)]; } else { throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error"); } } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
/** * Obtiene el valor de la columna "idUsuario" basado en la clave de api * @param $claveApi * @return null si este no fue encontrado */ private function obtenerIdUsuario($claveApi) { $comando = "SELECT " . self::ID_USUARIO . " FROM " . self::NOMBRE_TABLA . " WHERE " . self::CLAVE_API . "=?"; $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $claveApi); if ($sentencia->execute()) { $resultado = $sentencia->fetch(); return $resultado[self::ID_USUARIO]; } else { return null; } }
public function existeUsuario($correo) { $pdo = ConexionBD::obtenerInstancia()->obtenerBD(); $comando = "SELECT * FROM " . SELF::NOMBRE_TABLA . " WHERE " . self::CORREO . " = ?"; $sentencia = $pdo->prepare($comando); $sentencia->bindParam(1, $correo); $sentencia->execute(); $resultado = $sentencia->rowCount(); if ($resultado > 0) { return true; } else { return false; } }
private function eliminarFavorito($idUsuario, $favorito) { $idFestival = $favorito["idFestival"]; $idArtista = $favorito["idArtista"]; if (isset($idFestival)) { try { // Sentencia DELETE $comando = "DELETE FROM " . self::NOMBRE_TABLA_FESTIVAL . " WHERE " . self::USUARIOS_ID . "=? AND " . self::FESTIVALES_ID . "=?"; // Preparar la sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $idUsuario); $sentencia->bindParam(2, $idFestival); $sentencia->execute(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } } else { try { // Sentencia DELETE $comando = "DELETE FROM " . self::NOMBRE_TABLA_ARTISTA . " WHERE " . self::USUARIOS_ID . "=? AND " . self::ARTISTAS_ID . "=?"; // Preparar la sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $idUsuario); $sentencia->bindParam(2, $idArtista); $sentencia->execute(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } } }
private function eliminarAmigo($amigo) { $idUsuario1 = $amigo["idUsuario1"]; $idUsuario2 = $amigo["idUsuario2"]; try { // Sentencia DELETE $comando = "DELETE FROM " . self::NOMBRE_TABLA_RELACION . " WHERE " . self::ID_USUARIO1 . "=? AND " . self::ID_USUARIO2 . "=?"; // Preparar la sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $idUsuario1); $sentencia->bindParam(2, $idUsuario2); $sentencia->execute(); // Sentencia DELETE $comando = "DELETE FROM " . self::NOMBRE_TABLA_RELACION . " WHERE " . self::ID_USUARIO2 . "=? AND " . self::ID_USUARIO1 . "=?"; // Preparar la sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $idUsuario1); $sentencia->bindParam(2, $idUsuario2); $sentencia->execute(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Floristeria morea</title> <link href="bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="stylesheet"> <link href="css/estilos.css" rel="stylesheet"> </head> <body> <?php require "php/Clase_ConexionBD.php"; $conBd = new ConexionBD("tiendaonline"); //Crea una lista despegable que como value tendra el id del producto y visualizara el nombre y como name ldnombre (ld+nombre campo tabla) $sql = "select id,nombre from productos"; $conBd->CrearListaDespegableSql($sql); //Crea una formulario sin datos con 2 columnas (opcion de columnas 1,2,3,4) con todos los campos de la tabla productos $sql = "select * from productos"; $conBd->crearFormularioSql($sql, 2, "Formulario Productos vacio", false); //Crea una formulario con datos con 4 columnas (opcion de columnas 1,2,3,4) con todos los campos de la tabla productos $sql = "select * from productos where id=2"; $conBd->crearFormularioSql($sql, 4, "Formulario Productos con datos", true); //Crea un listado de los productos $sql = "select * from productos"; $conBd->listadoConsultaSql($sql, "LISTADO DE PRODUCTOS", "NO HAY PRODUCTOS"); //Crea un listado de los productos con una columna para poder hacer modificaciones en cada producto (se le pasa la pagina php) $sql = "select * from productos"; $conBd->listadoConsultaSqlConCambios($sql, "LISTADO DE PRODUCTOS A MODIFICAR", "NO HAY PRODUCTOS", "BAJA.PHP", 0); $conBd->cerrarBD();
public static function obtenerUltimasRutas() { try { $comando = "SELECT " . self::ID_RUTA . " , " . self::NOM_RUTA . "," . self::VALORACION . " , " . self::ID_CATEGORIA . "," . self::ID_USUARIO . " FROM " . self::NOMBRE_TABLA . " ORDER BY fechaCreacion DESC LIMIT 15 ;"; // Preparar sentencia $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); // Ejecutar sentencia preparada if ($sentencia->execute()) { return $sentencia->fetchAll(PDO::FETCH_ASSOC); } return array(); } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }
private function obtenerNombreFestival($idFestival) { try { $comando = "SELECT " . self::NOMBRE_FESTIVAL . " FROM " . self::NOMBRE_TABLA_FESTIVALES . " WHERE " . self::ID_FESTIVAL . " = '{$idFestival}' ;"; $sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($comando); $sentencia->bindParam(1, $idFestival, PDO::PARAM_STR); if ($sentencia->execute()) { http_response_code(200); return $sentencia->fetch(); } else { throw new ExcepcionApi(self::ESTADO_ERROR, "Se ha producido un error"); } } catch (PDOException $e) { throw new ExcepcionApi(self::ESTADO_ERROR_BD, $e->getMessage()); } }