我想要一个包含所有数据库信息(dbname、host、username、password)的通用 php 文件
但是当我在 index.php 中包含页面时,我收到了这个错误:
用户 'apache'@'localhost' 的访问被拒绝(使用密码:否)
连接.php
<?php
class dbconnect{
private $host = '**';
private $user = '**';
private $pass = '**';
public $con;
function Connect($db = '**') {
if($db=='**'){
$this->host="localhost";
$this->user="**";
$this->pass="**";
$db="**";
}else{
$this->host="**";
$this->user="**";
$this->pass="**";
}
$this->con = mysql_connect($this->host,$this->user,$this->pass);
if (!$this->con)
{
die('Could not connect: ' . mysql_error());
}
$blaa = mysql_select_db($db, $this->con);
mysql_query("SET NAMES UTF8");
return $blaa;
}
function Disconnect() {
//$this->con = mysql_connect($this->host,$this->user,$this->pass);
mysql_close();
}
}
?>
我确信 ** 信息是正确的,因为当我将其指定为:
$con=mysqli_connect("example.com","example","password","my_db");
在 index.php 中它可以工作