Skip to content
Advertisement

Connection refused to database (Symfony 5) [closed]

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

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

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

<?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);
    }
}

And I’m getting these errors

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement