I’m trying to connect my database to my app with Symfony but I keep getting errors. I specify that it’s not a local database. Also, I’m on Symfony 5 & PHP 7.4.
First, I put this in my .env file
JavaScript
x
DATABASE_URL="mysql://user_xxx:pass_xxx@host_xxx:3306/db_xxx?serverVersion=5.5.68-MariaDB"
All these informations seems to be good.
Next, here is my doctrine.yaml file
JavaScript
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.5.68-MariaDB'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App
And then to test the connection to db, I made this code
JavaScript
<?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class TestController extends AbstractController
{
/**
* @Route("/test", name="test")
*/
public function index(): Response
{
$em = $this->getDoctrine()->getManager();
$em->getConnection()->connect();
$connected = $em->getConnection()->isConnected();
var_dump($connected);
}
}
Could someone help me and tell me what i’m doing wrong ?
Advertisement
Answer
My problem is solved, I had to enable the extension “pdo_mysql” in my PHP.ini file. Thanks all for the help.