我有一個登錄腳本,但是當我進入它有COM一個錯誤:如何連接到庫MySQLi服務器
Undefined property: Users::$host in C:\wamp\www\userlogin\classes\class.database.php on line 8
有4個文件:
<?php
session_start();
include "classes/class.users.php";
if(isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$users->login($username, $password);
}
?>
<!DOCTYPE html>
<head>
<title>Basic Login Script</title>
</head>
<body>
<form method="POST" action="" name="login">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="login" value="Login">
</form>
</body>
</html>
<?php
class Database
{
public function __construct()
{
$host = 'localhost';
$user = 'root';
$pass = 'password';
$name = 'usersystem';
$this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->name);
if ($mysqli->connect_errno)
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
echo $mysqli->host_info . "\n";
}
} ?>
<?php
include "class.database.php";
class Users extends Database
{
public function login($username, $password)
{
$stmt = $this->mysqli->prepare("SELECT username, password FROM users WHERE username = ? and password = ? LIMIT 1");
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->num_rows == 1) {
while($stmt->fetch()) {
$_SESSION['username'] == $username;
header("Location: dashboard.php");
}
}
else
return false;
$stmt->close();
$stmt->free_result();
}
}
$users = new users(); ?>
//dashboard
<?php echo "error"; ?>
我用localhost/index.php
運行,3個文件class.database.php
和class.users.php
dahsboard.php
是在目錄:類
Mybe這是一個語法錯誤,但我不能找到它。 我已經在phpmyadmin中創建了一個數據庫並插入了數據。
任何人都可以幫助我嗎?
在數據庫改變$用戶__construct方法這個 - $>用戶,$主機這個 - $>主機等
如果我是你,我會去C:\ wamp \ WWW \用戶登陸\類\ class.database.php和第8行。 – ElSS 2014-10-17 21:04:54
'mysqli'不是服務器。它是PHP語言的「MySQL改進」擴展,允許您訪問MySQL服務器。 – Kamil 2014-10-17 21:23:12