我有一個問題,當我輸入登錄信息,我得到這個錯誤致命錯誤:調用一個非對象的成員函數prepare()。
Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\Remake Login Page\Classes\Mysql.php on line 22
的代碼Mysql.php:
<?php
require_once 'includes/constants.php';
class Mysql {
private $conn;
function _construct() {
$this->$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die
('There was a problem connecting to the database');
}
function verify_Username_and_Pass($un, $pwd) {
$query = "SELECT *
FROM users
WHERE username = ? AND password = ?
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
希望有人能幫助我。
在此先感謝。
你的構造函數是錯誤的,應該__construct() – hank
參見:http://stackoverflow.com/questions/5346186/pdo-call-to-a-member-function-準備在非對象 –