SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
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)); var_dump($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; // $stmt = $conn->prepare($sql); // $stmt->execute(22); // $records = $stmt->fetchAll(PDO::FETCH_ASSOC); // var_dump($records); // var_dump($records); // return $records; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)