【发布时间】:2013-11-23 07:43:52
【问题描述】:
我想要一个包含所有数据库信息(数据库名称、主机、用户名、密码)的通用 php 文件
但是当我包含页面时,在 index.php 中我得到了这个错误:
拒绝用户 'apache'@'localhost' 访问(使用密码:否)
connect.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 中有效
【问题讨论】: