Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error "compatible with PDO::query" in new PHP8

Tags:

php

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 DB\Sql::query($query, $parameters = []) must be compatible with PDO::query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) in C:\xampp\page\class\DB\Sql.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

like image 928
Ami Avatar asked Mar 10 '26 10:03

Ami


1 Answers

Remove "query" and use "run" instead.

like image 177
Flávio Alencar Avatar answered Mar 12 '26 00:03

Flávio Alencar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!