I am trying to write a wrapper class for mysqli, basically just to better handle errors, but I'm getting an error when I try to run any page on the website, not just specifically ones that call mysqli.
this is the error I get:
PHP Warning: Declaration of PricingMySql::query($query) should be compatible with mysqli::query($query, $resultmode = NULL) in \classes\PricingMySql.php on line 37
This is the class definition for PricingMySql:
class PricingMySql extends mysqli{
public function __construct() {
parent::__construct(Pricing_DBServerName, Pricing_UserName,
Pricing_Password, Pricing_DBName);
if($this->connect_errno){
throw new Exception("Failed to connect to MySQL: (". $this->connect_errno. ") ". $this->connect_error, $this->connect_errno);
}
}
public function query(string $query, int $resultmode = MYSQLI_STORE_RESULT) {
if(!$result = parent::query($query, $resultmode)) {
echo "Query Execution failed: (", $this->connect_errno, ") ", $query;
}
return $result;
}
According to php.net, the definition of the mysqli::query method is exactly the same
mysqli::query ( string $query [, int $resultmode = MYSQLI_STORE_RESULT ] ) : mixed
So why then do I get the warning? I tried changing my code so that $resultmode = null like it says in the warning:
public function query(string $query, int $resultmode = NULL) {
but that still results in the same warning. Where am I going wrong?
Edit to add: I got rid of the forced types:
public function query($query, $resultmode = MYSQLI_STORE_RESULT) {
but again, same warning.