-2

I want to deploy my Symfony5 project on to a remote shared hosting (Hostinger). I've already set up an account on Hostinger and I've also managed to create a database through their database module using "phpMyAdmin".

Now, how can I work with Doctrine if my database is already created and on Hostinger? All the examples I've seen when using Doctrine and Symfony5, create a local database and operate with it. Is it the same steps for a remote database already created?

In my Symfony5 project I've already installed the "symfony/orm-pack" and I've also updated my "DATABASE_URL" on the ".env" file as follows: DATABASE_URL="mysql://u811510647_guillemba:[db_password_hidden_for_obv_reasons]@127.0.0.1:3306/u811510647_containers?serverVersion=10.2"

The parameters of: [db_user, db_password, db_name and serverVersion] are all adapted on what Hostinger's remote database is telling me to enter.

The "symfony console doctrine:database:create" makes no sense if the database is already created no? How can I create an entity on this remote database with Doctrine?

I'd really appreciate some help, thanks a lot!

guillemba
  • 1
  • 3
  • Assuming your remote connection works then just [follow the docs](https://symfony.com/doc/current/doctrine.html#creating-an-entity-class). Symfony does not care. However it is much easier to work with a local database and then just transfer the database typically using a migration. It will be a bit of a learning curve. – Cerad Feb 18 '21 at 12:51
  • Thanks, I understand. The only thing when reading the docs is that, it starts with "php bin/console doctrine:database:create", and I don't understand what is this doing if my "DATABASE_URL" is pointing to a remote location and it is already created. What does it do if it's already created? – guillemba Feb 18 '21 at 13:01
  • It just returning an error telling you the database already exists. By the way noit sure what "creating an entity" means. Whats do you want to do ? Update the schema to your orm mapping ? – jona303 Feb 18 '21 at 13:10
  • 1
    @koyaanisqatsi This is why it's generally recommended to work locally and follow the docs until you get comfortable with the basics. You are not going to get very far with Symfony if you expect to just blindly follow steps without understanding what is going on. Think about it. What do you expect to happen if you try to create a database that already exists? What does creating a database even mean? What should you do if try create a database when you already have one? – Cerad Feb 18 '21 at 13:18
  • Thanks @Cerad. I agree that I should probably start with the basics by following the documentation. Cheers. – guillemba Feb 18 '21 at 14:26
  • @jona303 I meant creating an entity to represent the underlying data of the remote database. All the examples I have seen create an entity over a local database table. – guillemba Feb 18 '21 at 14:29
  • you want to create your entities object and mapping based on a existing schema that's on a remote server ? First of all I would `mysqldump` the remote database to work locally. Then I would follow this doc https://symfony.com/doc/current/doctrine/reverse_engineering.html – jona303 Feb 18 '21 at 14:38
  • @jona303 Thanks a lot! – guillemba Feb 18 '21 at 15:35

1 Answers1

1

It sounds like you have an existing database and you want to import the schema to your Symfony project?

php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity

Note: If you want to specify a specific database from your project then you can also pass in the em

--em=myconnectionname
Robert Saylor
  • 1,279
  • 9
  • 11