2
Well I got a class Sql
extending PDO
, but when I define a namespace the following error message appears when creating an object from the Sql class:
Fatal error: Class 'PDO-related classes' not found in var/www/html/DAO/classes/connected/Sql.php on line 3
it’s as if the PDO
was being called from inside the namespace I created, can anyone help me? I’m new to PHP
class below:
<?php
namespace classes\conexao;
class Sql extends PDO{
private $conn;
public function __construct(){
$this->conn = new PDO("mysql:host=localhost; dbname=dbphp7", "root", "123456");
}
private function setParams($statment, $parameters = array()){
foreach($parameters as $key => $value){
$this->setParam($statement, $key, $value);
}
}
private function setParam($statment, $key, $value){
$statment->bindParam($key, $value);
}
public function query($rawQuery, $params = array()){
$stmt = $this->conn->prepare($rawQuery);
$this->setParams($stmt, $params);
return $stmt->execute();
}
public function select($rawQuery, $params = array()):array{
$stmt = $this->query($rawQuery, $params);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function getConn() {
return $this->conn;
}
public function setConn($conn) {
$this->conn = $conn;
}
}
?>
Change to extends PDO
– Diego Schmidt
Thanks a lot, man, I hope I can contribute soon with the guys, thanks a lot
– Mestre Splinter