Skip to content

Instantly share code, notes, and snippets.

@alphanetEX
Created July 11, 2017 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphanetEX/95bfd44fd39dfec4d9a5be1006a5ea89 to your computer and use it in GitHub Desktop.
Save alphanetEX/95bfd44fd39dfec4d9a5be1006a5ea89 to your computer and use it in GitHub Desktop.
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