Fix splitting of database info. #576
This commit is contained in:
parent
3df1989f68
commit
bd0b24b034
1 changed files with 6 additions and 7 deletions
|
|
@ -24,19 +24,18 @@ if (!file_exists($argv[1]))
|
|||
$dotenv = new Dotenv();
|
||||
$dotenv->loadEnv(__DIR__.'/../../.env');
|
||||
|
||||
$user = $_ENV['DB_USER'];
|
||||
$pass = $_ENV['DB_PASSWORD'];
|
||||
$db_info = $_ENV['DATABASE_URL'];
|
||||
|
||||
// sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq
|
||||
// dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8
|
||||
|
||||
$result = preg_split("/[\/:@]/", $db_info);
|
||||
preg_match('/^mysql:\/\/(.*):(.*)@(.*):(.*)\/(.*)/', $db_info, $result);
|
||||
|
||||
$db_type = 'mysql:host=';
|
||||
$user = $result[3];
|
||||
$pass = $result[4];
|
||||
$ip_port = $result[5] . ':' . $result[6] . ';';
|
||||
$db_name = 'dbname=' . $result[7] . ';';
|
||||
$user = $result[1];
|
||||
$pass = $result[2];
|
||||
$ip_port = $result[3] . ':' . $result[4] . ';';
|
||||
$db_name = 'dbname=' . $result[5] . ';';
|
||||
$charset = 'charset=UTF8';
|
||||
|
||||
$dsn = $db_type . $ip_port . $db_name . $charset;
|
||||
|
|
|
|||
Loading…
Reference in a new issue