1 changed files with 26 additions and 6 deletions
@ -1,8 +1,28 @@ |
|||
<?php |
|||
try { |
|||
$dbh = new PDO("mysql:host=db-104.coowo.com:3306;dbname=appwms", 'masadaroot', 'x6h5E5p#u8y'); |
|||
$dbh->exec("set names utf8"); |
|||
$envFile = __DIR__ . '/../.env'; // .env 文件的路徑 |
|||
|
|||
if (file_exists($envFile)) { |
|||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|||
if ($lines !== false) { |
|||
foreach ($lines as $line) { |
|||
list($key, $value) = explode('=', $line, 2); |
|||
$key = trim($key); |
|||
$value = trim($value); |
|||
// 设置环境变量 |
|||
putenv("$key=$value"); |
|||
} |
|||
} |
|||
catch(PDOException $e) { |
|||
echo $e->getMessage(); |
|||
} |
|||
} |
|||
date_default_timezone_set("Asia/Taipei"); |
|||
$host = getenv('DB_HOST'); |
|||
$dbuser = getenv('DB_USERNAME'); |
|||
$dbpassword = getenv('DB_PASSWORD'); |
|||
$dbname = getenv('DB_DATABASE'); |
|||
|
|||
|
|||
try { |
|||
$dbh = new PDO("mysql:host=$host:3306;dbname=$dbname", $dbuser, $dbpassword); |
|||
$dbh->exec("set names utf8"); |
|||
} catch (PDOException $e) { |
|||
echo $e->getMessage(); |
|||
} |
|||
|
Loading…
Reference in new issue