putenv
Set the value of the environment variable
Function name: putenv()
Function Description: This function is used to set the value of an environment variable.
Applicable versions: All versions of PHP
usage:
bool putenv ( string $setting )
parameter:
$setting
: The environment variable and its value to be set, in the format "variable=value".Return value:
Example:
// 示例1:设置环境变量putenv("DB_HOST=localhost"); putenv("DB_USER=root"); putenv("DB_PASS=123456"); // 示例2:获取环境变量$host = getenv("DB_HOST"); $user = getenv("DB_USER"); $pass = getenv("DB_PASS"); echo "DB_HOST: " . $host . "<br>"; echo "DB_USER: " . $user . "<br>"; echo "DB_PASS: " . $pass . "<br>";
In the above example, three environment variables are first set through putenv()
function, namely the database host address, user name and password. Then, the values of these environment variables are obtained through getenv()
function and output them to the browser.