로그인 기능을 사용하고 있지만 알아낼 수없는 오류가 있습니다.클래스에 메소드가 없습니다.
이 내 모델 로그인 클래스입니다 :
class Login {
private $username;
private $password;
private $cxn; //database object
function __construct($username,$password)
{
//set data
$this->setData($username, $password);
//connect DB
$this->connectToDB();
// get Data
}
function setData($username, $password)
{
$this->username = $username;
$this->password = $password;
}
private function connectToDB()
{
include 'Database.php';
$connect = '../include/connect.php';
$this->cxn = new database($connect);
}
function getData()
{
$query = "SELECT * FROM anvandare WHERE anvandarnamn = '$this->username' AND losenord ='$this->'password'";
$sql = mysql_query($query);
if(mysql_num_rows($sql)>0)
{
return true;
}
else
{
throw new Exception("Användarnamnet eller Lösenordet är fel. Försök igen.");
}
}
function close()
{
$this->cxn->close(); //Here is the error it says "Method 'close' not found in class
}
}
마지막 기능은 "참조 된 방법은 대상 클래스에없는."
, 오류 " '가까운'클래스에서 찾을 수 없습니다 방법"을 제공합니다 여기내 데이터베이스 클래스입니다 :
class Database {
private $host;
private $user;
private $password;
private $database;
function __construct($filename)
{
if(is_file($filename)) include $filename;
else throw new exception("Error!");
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
$this->connect();
}
private function connect()
{
//Connect to the server
if(!mysql_connect($this->host, $this->user, $this->password))
throw new exception("Error, not connected to the server.");
//Select the database
if(!mysql_select_db($this->database))
throw new exception("Error, no database selected");
}
function close()
{
mysql_close();
}
}
경로는 올바른들입니다 그것은 그렇지 않습니다. 어떤 오류가있을 수 있습니까? 대신 close()를 기능의
오래된 mysql_ * 함수를 사용하지 말고 준비된 구문으로 PDO를 사용하는 법을 배우십시오. –
실제 문제를보기가 어렵습니다. 이 객체를 정확히 사용하는 방법을 지정할 수 있습니까? – stefan