我可以在PHP的函数中使用常量吗?
是否可以在 PHP 函数中使用 PHP 常量?
// in a different file
DEFINE ('HOST', 'hostname');
DEFINE ('USER', 'username');
DEFINE ('PASSWORD', 'password');
DEFINE ('NAME', 'dbname');
// connecting to database
function database()
{
// using 'global' to define what variables to allow
global $connection, HOST, USER, PASSWORD, NAME;
$connection = new mysqli(HOST, USER, PASSWORD, NAME)
or die ('Sorry, Cannot Connect');
return $connection;
}