我创建了一个类,将我的类扩展到 PHP 中的 mysqli 类,看到这些错误我真的很震惊
Warning: Missing argument 1 for BeatBeast_Database::__construct(), called in C:\xampp\htdocs\beatbeast\login.php on line 11 and defined in C:\xampp\htdocs\beatbeast\includes\Db\BeatBeast_Db.php on line 6
Warning: Missing argument 2 for BeatBeast_Database::__construct(), called in C:\xampp\htdocs\beatbeast\login.php on line 11 and defined in C:\xampp\htdocs\beatbeast\includes\Db\BeatBeast_Db.php on line 6
Warning: Missing argument 3 for BeatBeast_Database::__construct(), called in C:\xampp\htdocs\beatbeast\login.php on line 11 and defined in C:\xampp\htdocs\beatbeast\includes\Db\BeatBeast_Db.php on line 6
Warning: Missing argument 4 for BeatBeast_Database::__construct(), called in C:\xampp\htdocs\beatbeast\login.php on line 11 and defined in C:\xampp\htdocs\beatbeast\includes\Db\BeatBeast_Db.php on line 6
这是 BeatBeast_Db.php
<?php
class BeatBeast_Database extends mysqli
{
protected $r = 'Something';
public function __construct($db_host,$db_username,$db_password,$db_name)
{
parent::__construct($db_host,$db_username,$db_password,$db_name);
if(mysqli_connect_error())
{
die('Connect Error (' . mysqli_connect_errno() . ')' . mysqli_connect_error());
}
}
public function close()
{
$this->close();
}
}
require_once("db_constants.inc.php");
$conn = new BeatBeast_Database("localhost", "root", "myPass", "beatbeast");
这是我的 login.php
<?php require_once("./includes/Utilities.php") ;?>
<?php require_once("./includes/Db/DatabaseUtilities.php"); ?>
<?php require_once("./includes/Db/Accounts.php");?>
<?php require_once("./includes/Db/BeatBeast_Db.php"); ?>
<?php
if(isset($_POST['submit'])){
require_once("./includes/process_form.inc.php");
$hashedPass = crypt($password,$username);
$accounts = new Accounts();
$accounts->showMessage();
第 11 行是
$accounts = new Accounts();
如果你们有兴趣,这里是我的 Accounts 课程
require_once("BeatBeast_Db.php");
Class Accounts extends BeatBeast_Database
{
private $accnt_id;
private $username;
private $email;
function info()
{
echo "{$this->accnt_id} {$this->username} {$this->email}";
}
public static function getIdByUsername($username)
{
global $conn;
$sql = "SELECT accnt_id FROM accounts WHERE username = '{$username}'";
$rs = $conn->query($sql);
$found = $rs->fetch_array();
return $found;
}
public function showMessage(){
echo "{$this->r}";
}
public static function getUsernameById($id)
{
global $conn;
$sql = "SELECT username FROM accounts WHERE accnt_id = $id ";
$rs = $conn->query($sql);
$found = $rs->fetch_array();
return $found;
}
public function getAccntId()
{
return $this->accnt_id;
}
public function getUsername()
{
return $this->username;
}
public function getEmail()
{
return $this->email;
}
}