Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
consulta php slim
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
//Obtener todos los clientes
$app->get('/cliente', function(Request $request, Response $response){
$consulta = "SELECT * FROM clientes";
try{
// Instanciar la base de datos
$db = new db();
// Conexión
$db = $db->conectar();
$ejecutar = $db->query($consulta);
$clientes = $ejecutar->fetchAll(PDO::FETCH_OBJ);
$db = null;
//Exportar y mostrar en formato JSON
echo json_encode($clientes);
} catch(PDOException $e){
echo '{"error": {"text": '.$e->getMessage().'}';
}
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment