John Davidson

php - Doctrine 2 - MySql : multiples 'BASE TABLE' queries added to every views

0 comments
Message:


Do you know why every views of my Symfony 4.4.25 website using Doctrine ORM 2.9.3 add between 3 and 10 queries like this:


SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'

The database is MySQL version 5.7




My Answer:
One of the main advantages of using Doctrine 2 with MySQL is the ability to easily work with multiple database connections within the same application. This can be useful in scenarios where you need to interact with multiple databases or switch between different database connections based on certain conditions.

To set up multiple database connections in Doctrine 2 with MySQL, you can define multiple connection configurations in your application configuration file (usually `config.yml` or `config.php`). Each connection configuration should specify the database driver (MySQL), host, port, database name, username, and password.

Here's an example of how you can define multiple database connections in a Symfony application using Doctrine 2:

yaml
# config.yml

doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: 3306
dbname: database1
user: root
password: root
charset: UTF8

second_connection:
driver: pdo_mysql
host: localhost
port: 3306
dbname: database2
user: root
password: root
charset: UTF8


Once you have defined the multiple database connections in your configuration file, you can easily switch between them in your application code by specifying the connection name when creating a new EntityManager instance:

php
// Get the default entity manager
$entityManager1 = $this->getDoctrine()->getManager('default');

// Get the second entity manager
$entityManager2 = $this->getDoctrine()->getManager('second_connection');


With this setup, you can now work with multiple database connections in your application using Doctrine 2 with MySQL. This can be particularly useful in scenarios where you need to interact with multiple databases or switch between different database connections based on certain conditions.

Rate this post

3 of 5 based on 1353 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us