I have a Sql class that was working perfectly fine until PHP7. Now, using PHP8, I get the error shown below.
Fatal error: Declaration of DBSql::query($query, $parameters = []) must be compatible with PDO::query(string $query, ?int $fetchMode = null, mixed …$fetchModeArgs) in C:xampppageclassDBSql.php on line 15
Nothing has changed in the code!But I really can’t understand what’s wrong!
My Sql class has a “query” function like this (line 15)
public function query($query, $parameters=array()) { $statement = $this->conection->prepare($query); foreach ($parameters as $key => $value) { $statement->bindValue($key,$value); } $statement->execute(); return $statement; }
The “$this->conection calls this:
private $conection; public function __construct() { $this->conection = new PDO("mysql:host=".dbHost.";dbname=".dbDb,dbUsuario,dbSenha); }
Thanks to anyone who can help
Advertisement
Answer
Remove “query” and use “run” instead.