2010-05-01 2 views
0

저는 OOP 세계로 들어가기를 바랍니다. 이것이 n00bish 질문 인 경우 용서해주십시오.데이터베이스 클래스가 내 데이터베이스에 올바르게 연결되어 있지 않습니다.

이것은 내가 index.php에있는 것입니다 :

$dbObj = new Database(); 
$rsObj = new RS($dbObj); 

이 데이터베이스 클래스입니다 : 내가 일을 단순화에 바로 connect() 방법을 단축했습니다

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()); 
    } 
} 

. 아마 당신은 볼 수 있듯이

class RS 
{ 
    private $username; 
    private $password; 

    function __construct($dbObj) 
    { 
     // We need to get an account from the db 
     $dbObj->connect(); 

    } 
} 

, 나는 액세스하고 내 RS 클래스의베이스 클래스를 사용해야합니다

는 RS 클래스입니다.

경고 :로 mysql_connect() [function.mysql-연결] : 나는 페이지를로드 할 때이 오류를 얻을 사용자 'ODBC'에 대한 액세스가 거부 를 @ 'localhost를' (사용 암호 : 아니오) C에서 :

것은 라인 (22)에 database.class.php 나는 그것이 사용자로 ODBC을 사용할 필요가 있다는 생각이있어 아무 생각이있다 \ \ XAMPP \ htdocs를 \ 포함 ... 나는이 물건을하는 것에 대해 읽었고, 내가 모을 수있는 것으로부터 올바르게하고있다.

누구든지 나를 빌려 줄 수 있습니까?

감사합니다.

+0

blerh, 제발 V 대답을 받아들이십시오. – webbiedave

답변

2

connect()의 속성 이름이 클래스의 속성 이름과 일치하지 않습니다.

변경 :

$this->link = mysql_connect($this->dbHost, $this->dbUser, $this->dbPasswd); 

변경 :

$this->link = mysql_connect($this->db_host, $this->db_user, $this->db_passwd); 

으로

$this->selection = mysql_select_db($this->db_name, $this->link); 

사람 :

$this->selection = mysql_select_db($this->dbName, $this->link); 
관련 문제