You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

30 lines
847 B

<?php
$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");
}
}
}
date_default_timezone_set("Asia/Taipei");
$host = getenv('DB_HOST');
$dbuser = getenv('DB_USERNAME');
$dbpassword = getenv('DB_PASSWORD');
$dbname = getenv('DB_DATABASE');
$link = mysqli_connect($host,$dbuser,$dbpassword,$dbname);
if($link){
mysqli_query($link,'SET NAMES utf8');
// echo "正確連接資料庫";
}
else {
echo "不正確連接資料庫</br>" . mysqli_connect_error();
}
?>