-1
You’re making the following mistake:
Warning : PDO :: query(): SQLSTATE [HY000]: General error: the mode must be an integer in C: xampp htdocs joel_php curso_hcode DAO
sql.php on line 34Fatal error : Error not detected: Call to a member function execute () on bool in C: xampp htdocs joel_php curso_hcode
DAO sql.php: 35 Stack tracking: #0 C: xampp htdocs
joel_php curso_hcode DAO indexx.php (7): Sql-> select ('SELECT * FROM t ...') #1 {main} released in C: xampp htdocs joel_php
curso_hcode DAO sql.php on line 35
Code:
<?php
class Sql extends PDO{
private $conn;
public function __construct(){
$this->conn = new PDO("mysql:host=localhost;dbname=dbphp7","root","");
echo "funcione";
}
private function setParams($statment,$paraneters = array()){
foreach($paraneters as $key =>$value){
$this->setParam($statment,$key,$value);
}
}
private function setParam($statment,$key,$value){
$statment->bindParam(":{$key}",$value);
}
public function execQuery($rawQuery,$params = array()){
$stmt = $this->conn->prepare($rawQuery);
$this->setParams($stmt,$params);
$stmt->execute();
return $stmt;
}
public function select($rawQuery,$params = array()):array{
$stmt = $this->conn->query($rawQuery,$params);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
?>
Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.
–
Probably gave error in the query
$stmt = $this->conn->query($rawQuery,$params);
and the value of$stmt
isFALSE
implying that$stmt->execute();
is equivalent toFALSE->execute();
generating the error.– Augusto Vasques
@Augustovasques then what should be changed in my code to prevent this error? could help me?
– Joel Neres
Important [Dit] to post and exchange the code for a [mcve] of the exact part of the doubt. To understand what kind of question serves the site and, consequently, avoid closures and negativities worth reading What is the Stack Overflow and the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco
With the information presented in the question it is impossible to determine a solution.
– Augusto Vasques
@Augustovasques I will try to edit the question and try to clarify it better! very obg for your help
– Joel Neres