bindParam Erreur 500 when I put the code in OOP

  php

I’m a student and I can’t solve this problem. This code worked fine before I putted in a OOP structure. Since I created the Model, it’s sending me a 500 error (it seems to be around the bindParam).

Can someone help me please ?

Thank you very much !

class DbModel
{
private $dbConnect;

function __construct()
{
  $this->dbConnect = new DbConnect();
}


public function executeQuery($sql, $data)
{
    $conn = $this->dbConnect->dbConnect();
    $stmt = $conn->prepare($sql);
    $values = array_values($data);
    $types = str_repeat('s', count($values));
    $stmt->bindParam($types, ...$values);
    $stmt->execute();
    return $stmt;
    var_dump($stmt);
}

public function selectOne($table, $conditions)
{
    $conn = $this->dbConnect->dbConnect();
    $sql = "SELECT * FROM $table";

    $i = 0;
    foreach ($conditions as $key => $value) {
        if ($i === 0) {
            $sql = $sql . " WHERE $key=?";
        } else {
            $sql = $sql . " AND $key=?";
        }
        $i++;
    }

    $sql = $sql . " LIMIT 1";
    $stmt = $this->executeQuery($sql, $conditions);
    $records = $stmt->fetchAll(PDO::FETCH_ASSOC);
    return $records;
}

}

Source: Ask PHP

LEAVE A COMMENT