LaLiga-BackEnd/src/Controller/AdminController.php

32 lines
977 B
PHP

<?php
namespace DMD\LaLigaApi\Controller;
use PDO;
use PDOException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class AdminController extends AbstractController
{
#[Route('/admin/db-check', name: 'app_check_db', methods: ['GET'])]
public function index(): Response
{
$host = 'db.dyb-tech.com';
$dbname = 'laliga';
$username = 'mamb';
$password = 'lakers06';
try {
$dbConnection = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return new JsonResponse("Connected successfully");
}
catch(PDOException $e)
{
return new JsonResponse("Connection failed: " . $e->getMessage());
}
}
}