我只是冒险进入OOP世界,所以如果这是一个n00bish问题,请原谅我。
这就是我在index.php上的资料
$dbObj = new Database();
$rsObj = new RS($dbObj);这是数据库类:
class Database
{
private $dbHost;
private $dbUser;
private $dbPasswd;
private $dbName;
private $sqlCount;
function __construct()
{
$this->dbHost = 'localhost';
$this->dbUser = 'root';
$this->dbPasswd = '';
$this->dbName = 'whatever';
$this->sqlCount = 0;
}
function connect()
{
$this->link = mysql_connect($this->db_host, $this->db_user, $this->db_passwd);
if(!$this->link)
$this->error(mysql_error());
$this->selection = mysql_select_db($this->db_name, $this->link);
if(!$this->selection)
$this->error(mysql_error());
}
}我把它简化为connect()方法来简化事情。
这是RS类:
class RS
{
private $username;
private $password;
function __construct($dbObj)
{
// We need to get an account from the db
$dbObj->connect();
}
}正如您可能看到的,我需要访问和使用RS类中的数据库类。但是当我加载页面时,我会得到这个错误:
警告: mysql_connect() function.mysql-connect:拒绝对第22行C:\xampp\htdocs\includes\database.class.php中的用户'ODBC'@'localhost‘(使用密码: NO)的访问
问题是,我不知道它是从哪里得到的,它需要使用ODBC作为用户.我读过关于做这件事的文章,据我所知,我做得很正确。
有人能帮我一下吗?
谢谢。
发布于 2010-05-01 18:53:35
connect()中的属性名称与类的属性名称不匹配。
更改:
$this->link = mysql_connect($this->db_host, $this->db_user, $this->db_passwd);至:
$this->link = mysql_connect($this->dbHost, $this->dbUser, $this->dbPasswd);和改变:
$this->selection = mysql_select_db($this->db_name, $this->link);至:
$this->selection = mysql_select_db($this->dbName, $this->link);https://stackoverflow.com/questions/2751137
复制相似问题