2013-09-01 2 views
-3

이 부분에 오류 (**Fatal Error : Call to undefined method Database::query()**)가 있습니다.이 부분이 어디서 왔는지 모르겠습니다. 나는이 if($result = $this->getConn()->query($query) 내 쿼리를 변경 한 경우 난 그냥 내 생성자치명적인 오류 : 정의되지 않은 메서드를 호출하십시오. Database :: query()

Class Database{ 

public function __construct(){ 

    $this->getConn(); 
} 
public function getConn(){ 
    return new mysqli("localhost", "root", "", "os_db"); 
} 
public function select($query){ 
    $data = array(); 
    if($result = $this->query($query)){ 
     while($row = $result->fetch_assoc()){ 
      $data[] = $row; 
     } 
    }else{ 
     $data = array(); 
    } 
return $data; 
} 
} 

을 변경하기 때문에 ..이 .. 난 그냥이 $this->query($query)

+0

, 그리고 전에 무엇 이었습니까 ? – Foo

+0

'$ this-> query ($ query)''Database :: query ($ query) '와 동등합니다. –

+1

오류 메시지를 여러분의 말로 반복하십시오. 또한 파일 이름과 줄 번호가 무엇인지 (오류 메시지에 있음) 알려주십시오. 오류의 원인을 이해해야합니다. –

답변

-2
Class Database { 

    public function __construct() { 

    $this->getConn(); 

    } 

    public function getConn() { 

    $db = new mysqli("localhost", "root", "", "os_db"); 
    $this->db = $db; 

    } 

    public function select($query) { 

    $data = array(); 

    if($result = $this->db->query($query)){ 

     while($row = $result->fetch_assoc()){ 

     $data[] = $row; 

     } 

    } else { 

     $data = array(); 

    } 

    return $data; 

    } 

} 
같이 할 것이다 연결을 호출 할 필요가 있다는 어쨌든이 완벽하게 작동

또는 대신 매번 클래스가 호출 연결, 당신은 같은 것을 할 수 있습니다 : 당신이 당신의 생성자를 변경 했는가

Class Database { 

    public function __construct() { 

    } 

    public function getConn() { 

    $db = new mysqli("localhost", "root", "", "os_db"); 
    $this->db = $db; 

    } 

    public function select($query) { 

    $this->getConn(); 

    $data = array(); 

    if($result = $this->db->query($query)){ 

     while($row = $result->fetch_assoc()){ 

     $data[] = $row; 

     } 

    } else { 

     $data = array(); 

    } 

    return $data; 

    } 

} 
+0

@downvoter, reason for downvotting? –

+0

OOP에 대한 더 많은 경험이 필요합니다. –

+0

@YourCommonSense와 같은 부분이 있습니까? –

관련 문제