A
A
Alexander2016-10-17 14:20:22
Laravel
Alexander, 2016-10-17 14:20:22

How to choose a server when connecting to a database?

dc061e25289c4e38ac0d0ff5c53bc9d3.png

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'https://my-site.com/'),
            'port' => env('DB_PORT', ''),
            'database' => env('DB_DATABASE', 'my_name'),
            'username' => env('DB_USERNAME', 'my_name'),
            'password' => env('DB_PASSWORD', 'my_pas'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

Mistake:
PDOException in Connector.php line 119:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

How can I specify the server in the settings?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Pochepko, 2016-10-17
@kentuck1213

laravel.su/docs/5.0/database#read-write-connections

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'https://my-site.com/'),
            'port' => env('DB_PORT', ''),
            'database' => env('DB_DATABASE', 'my_name'),
            'username' => env('DB_USERNAME', 'my_name'),
            'password' => env('DB_PASSWORD', 'my_pas'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
'mysql2' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'https://my-site2.com/'),
            'port' => env('DB_PORT', ''),
            'database' => env('DB_DATABASE', 'my_name2'),
            'username' => env('DB_USERNAME', 'my_name3'),
            'password' => env('DB_PASSWORD', 'my_pas4'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

laravel.su/docs/5.0/database#accessing-connections
DB::connection('mysql')->table('...')->get(); // Выбор из первого соединения
DB::connection('mysql2')->table('...')->get(); // Выбор из второго соединения

S
Sergeyj, 2016-10-17
@sayber

.env

DB_HOST=localhost
DB_DATABASE=my_name
DB_USERNAME=my_name
DB_PASSWORD=my_pas

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question