Hello.

How can you organize a connection to the necessary database, depending on the site we visited? Suppose there are sites:
test1.site.ru
test2.site.ru
test3.site.ru

and a common configuration file with connection data. I realized that this can be done through $_SERVER['SERVER_NAME'] . It turns out, the database to which we connect must have a name, which is the address of the site. Are there any other options?

  • @ aa22, Try to write more detailed questions. Explain what you see the problem, how to reproduce it, etc. - terantul

1 answer 1

You can use such a crutch.

 // Ассоциативный массив с ΠΈΠΌΠ΅Π½Π΅ΠΌ Π‘Π”, Ρ‚Π°ΠΊΠΈΠ΅ ΠΆΠ΅ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ для пароля ΠΈ ΡŽΠ·Π΅Ρ€Π° $data = array( 'site1.ru' => 'db_name1', 'site2.ru' => 'db_name2', 'site3.ru' => 'db_name2' ); // Π’Π΅ΠΊΡƒΡ‰ΠΈΠΉ Π΄ΠΎΠΌΠ΅Π½ $current_site = $_SERVER['SERVER_NAME']; // Π’Π΅ΠΊΡƒΡ‰ΠΈΠ΅ имя Π±Π°Π·Ρ‹ Π΄Π°Π½Π½Ρ‹Ρ… $get_current_dbname = $data[$current_site]; 

But I would not use such an architecture :)

  • How to do this, I know. ) I would find out if there are any other options. - aa22
  • @ aa22 get separate applications and give everyone a base;) - E_p