Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class db {
- private $dbhost = "mysql.hostinger.com.ar";
- private $dbuser = "(mi usuario)";
- private $dbpass = "(mi pass)";
- private $dbname = "(mi bd)";
- public function connect(){
- $mysql_connect_str = "mysql:host=$this->dbhost;dbname=$this->dbname";
- $dbConnection = new PDO($mysql_connect_str, $this->dbuser, $this->dbpass);
- $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- return $dbConnection;
- }
- }
- <?php
- use PsrHttpMessageServerRequestInterface as Request;
- use PsrHttpMessageResponseInterface as Response;
- $app->group('/usuario/', function () {
- $app = new SlimApp;
- $this-> get('', function(Request $request, Response $response){
- $sql = "select * from usuario";
- try{
- $db = new db();
- $db = $db->connect();
- $stmt = $db->query($sql);
- $usuario = $stmt->fetchAll(PDO::FETCH_OBJ);
- $db = null;
- echo json_encode($usuario);
- } catch(PDOException $e){
- echo '{"error": {"text": '.$e->getMessage(). '}';
- }
- });
- RewriteEngine On
- # Some hosts may require you to use the `RewriteBase` directive.
- # If you need to use the `RewriteBase` directive, it should be the
- # absolute physical path to the directory that contains this htaccess file.
- #
- # RewriteBase /
- Header add Access-Control-Allow-Origin "*"
- Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
- Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteRule ^(.*)$ index.php [QSA,L]
- <?php
- use PsrHttpMessageServerRequestInterface as Request;
- use PsrHttpMessageResponseInterface as Response;
- require '../vendor/autoload.php';
- require '../app/config/db.php';
- $app = new SlimApp(["settings" => $config]);
- $container = $app->getContainer();
- $capsule = new Capsule;
- $capsule->addConnection($config['db']);
- $capsule->setEventDispatcher(new Dispatcher(new Container));
- $capsule->bootEloquent();
- require '../app/route/usuario.php';
- $app->run();
Add Comment
Please, Sign In to add comment