I have the following code, where I want to instantiate the class
Username by $object = new Username
. The class Username extends to class Database (which is the class in the require_once()
command). And I get the error Fatal error: Uncaught Error: Class 'Username' not found in..... But when I change class Username extends Database
to class Username
(i.e., When it doesn't extend anymore to class Database), I get the error Fatal error: Uncaught Error: Call to undefined method Username::some() in..... I don't know what's my mistake..
<?php
require_once 'database.class.php';
if(isset($_POST['some'])){
$sql = 'SELECT * FROM noti WHERE name=:name';
$params = [
'name' => $_POST['some']
];
$object = new Username;
$number = $object->some($sql, $params);
if($number>0){
echo 'Username Exists.';
}
else{
echo '';
}
}
class Username extends Database{
public function some($sql, $params){
return $this->num_rows($sql, $params);
}
}