tenhos as 3 seguintes classes:
<?php
class Sql extends PDO{
private $conn;
//conexão com o banco
public function __constuct(){
$this->conn = new PDO("mysql:host=localhost;dbname=php7","root","root");
}
private function setParams($statment, $parameters = array()){
foreach(parameters as $key => $value) { //associar os parametros ao comando.//chave e o valor
$this->bindParam($key, $value);
}
}
private function setParam($statment, $key, $value){
$statment->bindParam($key, $value);
}
public function query($rawQuery,$params = array()){ //1-parametro a ser tratato e 2 os dados
$stmt = $this->$conn->prepare($rawQuery); //
$this->setParams($stmt, $params);
$stmt->execute();
return $stmt;
}
public function select ($rawQuery, $params = array()):array
{
$stmt = $this->query($rawQuery, $params);
$stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
<?php
spl_autoload_register(function($class_name){
$filename = $class_name.".php";
if(file_exists(($filename))){
require_once($filename);
}
});
?>
<?php
require_once("config.php");
$sql = new Sql();
$usuarios = $sql->select("SELECT * FROM tb_usuarios");
echo json_encode($usuarios);
?>
e esta dando o erro :
Fatal error: Uncaught TypeError: PDO::__construct() expects at least 1 parameter, 0 given in C:\xampp\htdocs\DAO\index.php:5 Stack trace: #0 C:\xampp\htdocs\DAO\index.php(5): PDO->__construct() #1 {main} thrown in C:\xampp\htdocs\DAO\index.php on line 5
o engrçado é que peguei em uma videoaula e esta igual ao do professor
diz que tem q passar um parametro, mas no dele não tem parametro