0

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: 'App\Entity'
            alias: App

And then to test the connection to db, I made this code

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

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 ?

  • Quite a few possible reasons. Server isn't running. Server is running but on a different port other than 3306. Firewall issues. – ewokx Jan 18 '21 at 08:27
  • Did you grant access for user to use remote : https://stackoverflow.com/questions/6239131/how-to-grant-remote-access-permissions-to-mysql-server-for-user – Lounis Jan 18 '21 at 11:31
  • Yes, all access are granted –  Jan 18 '21 at 14:53

2 Answers2

0

My problem is solved, I had to enable the extension "pdo_mysql" in my PHP.ini file. Thanks all for the help.

-1

First change the port to 3307 or 3308

Like the following example:

DATABASE_URL="mysql://user_xxx:pass_xxx@host_xxx:3308/db_xxx?serverVersion=5.5.68-MariaDB