Interview answer
Laravel connects to MySQL through environment variables in .env. The main configuration is exposed through config/database.php.
Code
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=shop
DB_USERNAME=root
DB_PASSWORD=secret
Then clear cached configuration:
php artisan config:clear
php artisan migrate
Laravel uses PDO underneath, while Eloquent provides the ORM layer.
Real-project scenario
For a production application, I would avoid committing .env to Git. Credentials should come from environment variables or a secrets manager. I would also use a dedicated MySQL user with only the permissions the application needs rather than using root.
0 comments:
Post a Comment
Thanks