クラスを 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;
}
}