A basic and lean recipe for connecting to MySQL in Symfony3.
This application will connect to the local mysql server, create a new database
called psd
and a new table inside this called
product
. When the application is loaded in the
browser, a Product object will be inserted into the database, and the details of
this will be displayed on the page.
git
php v5.5.9
composer
MySQL
$ mkdir -vp php-symfony-dbconnection
$ cd php-symfony-dbconnection
$ git clone https://github.com/benjaminvickers/php-symfony-dbconnection.git .
$ composer install
Enter the database connection details when prompted by composer. Otherwise you
can edit the details in the app/config/parameters.yml file. Remember the database
name should be set to psd
.
$ sudo service mysql start
$ php bin/console doctrine:database:create
$ php bin/console doctrine:schema:update --force
$ php bin/console server:run