從資料庫表中獲取 Json 資料(REST API)

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$app = new \Slim\App;

$app->get('/employee/view', function ($req, $res) {

    $con = new mysqli('localhost','USERNAME','PASSWORD','DATABASE');

    $query = $con->query("SELECT * FROM employee"); 
    while ($row = $query->fetch_assoc()) {
        $data[] = $row;
    }
    return $res->withJson($data); 
});

$app->run();