Forem

Hanane Kacemi
Hanane Kacemi

Posted on • Edited on

4

Symfony and Database

I'm having free time these days so I decided to go back to learn symfony. I picked up a course about doctrine and symfony. I will post my notes here, feel free to leave a comment, I am open to all suggestions.

Doctrine Installation :

Symfony 5 doesn’t come with a database layer when installing it, to be able to store data in a Database we need to add a library for that, like Doctrine. run : composer require orm

orm is an alias for a library called symfony/orm-pack

Pack is a shortcut to install several packages using one command, for example if we check the github repo of orm-pack, we see that it contains only a composer.json file where we have all dependencies(packages) needed for Doctrine.

Symfony and Docker :

Once the installation is done, you will notice that Symfony Flex added a docker-compose.yml file. Instead of using a local Database (ex :mysql) and attach it to our project let's take advantage of docker and the automatic configuration added by Flex.

docker-compose file

Check that Docker is installed on your machine, and then run :
docker compose up -d

To see the mysql Docker container, run :
docker compose ps

To connect to mysql :
docker compose exec database mysql -u root --password=password

Without Docker, you need to configure the environment variable DATABASE_URL in the .env file. Since we are using the local symfony server (by running symfony serve -d) we don’t need that, because when the symfony binary detects the docker-compose.yml file it reads all the config and environment variables of running services and make them available for our app.
You can run symfony var:export --multiline to see the value of environment variables.

To stop a container :
docker compose stop

That's all for today :)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay