我收到了这些错误:
警告:mysqli_real_escape_string()要求参数1为mysqli,在第44行的C:\ xxx \ database.php中给出null
警告:mysqli_real_escape_string()要求参数1为mysqli,在第44行的C:\ xxx \ database.php中给出null
警告:mysqli_query()期望参数1为mysqli,在第31行的C:\ xxx \ database.php中给出null
我已正确连接数据库连接。当我运行我的文件时,我收到这些错误:
//database.php
<?php
require_once ("config.php");
class MySQLDatabase {
private $connection;
function _construct() {
$this->open_connection();
}
public function open_connection() {
$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
die("Database connection failed:" .
mysqli_connect_error() .
"( " . mysqli_connect_errno() . ")"
);
}
}
public function close_connection() {
if (isset($this->connection)) {
mysqli_close($this->connnection);
unset($this->connection);
}
}
public function query($sql) {
$result = mysqli_query($this->connection, $sql); <<line 31
$this->confirm_query($result);
return $result;
}
private function confirm_query($result) {
if (!$result) {
die("Database query failed.");
}
}
public function escape_value($string) {
$escaped_string = mysqli_real_escape_string($this->connection, $string); <<line 44
return $escaped_string;
}
}
$database = new MySQLDatabase();
$db =& $database;
?>
运行&#39; user.php&#39;
public static function authenticate($email="", $password="") {
global $database;
$email = $database->escape_value($email);
$password = $database->escape_value($password);
/*SQL statements*/
}
&#39;的config.php&#39;
<?php
// Database Constants
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost:3306");
defined('DB_USER') ? null : define("DB_USER", "username");
defined('DB_PASS') ? null : define("DB_PASS", "password");
defined('DB_NAME') ? null : define("DB_NAME", "databasename");
?>
到底出了什么问题?