Doctrine setup

Contents
ORM bundle
DATABASE_URL
Create the database
Check the connection

ORM bundle

Doctrine is the database layer of Symfony. One meta package, the ORM pack, installs the bundle, the configuration files, and the console commands:

Install the ORM pack

composer require symfony/orm-pack

[OK] The ORM pack is installed and configured

You run this command once per project. Later lessons use the commands it installs.

DATABASE_URL

Connection details live in the .env file as a single URL. Driver, user, password, host, and database name all sit inside DATABASE_URL:

DATABASE_URL="postgresql://user:secret@127.0.0.1:5432/blog?serverVersion=16"

Swap the values to match your own database server. The course examples use a database named blog.

Create the database

Build the empty database from that URL with one console command. Run it inside the project folder:

Create the database from DATABASE_URL

php bin/console doctrine:database:create

Created database `blog` for connection named default

The command only creates the database itself. Tables arrive later through migrations.

Check the connection

That success message proves three things at once: the URL parses, the server runs, and the credentials work.

A connection error at this step almost always means a typo in the URL or a stopped database server. Compare the error message with the value in .env before changing anything else.

Next: Entities

Article author: Arthur Isaev

Related articles
Development with PHP
What is Symfony and where it runs
Install Symfony
Your first page
Routes
Controllers
Twig basics
Twig advanced
Doctrine setup
Entities
Migrations
Repositories
Relations
Forms
Validation
Services and DI
JSON controllers
Serializer
Security intro
Users
Login form
Voters
Console commands
Events
Messenger
Mailer
Cache
Sessions
CSRF
Translations
Dotenv and env
Profiler
Testing
Fixtures
Pagination
File uploads
API Platform in one lesson
DQL
Transactions
Migrations advanced
Security advanced
HTTP client
Scheduler
Webhooks
Asset Mapper
Deployment
Performance
Capstone: blog
Capstone: JSON API
Modern Symfony tour
Hero roadmap: the whole course on one page

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: