如何声明数据库连接全局,以便每个类只使用1个config.php文件?
我试过
global $db;
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'DATABASe');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
class login_class
{
function login($email,$pass)
{
然后我的班级
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
$query=mysqli_query($db,
"
SELECT
*
FROM
users
WHERE
email='$email'
AND password = '$pass'
");
while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$userkey=$row['user_key'];
$password=$row['password'];
}
但这不起作用......
我有10多个clases,我在那里使用所以我更喜欢只有1个配置文件,但我尝试的只是工作...