Warning : PDO :: query(): SQLSTATE [HY000]?

Asked

Viewed 24 times

-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 34

Fatal 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 is FALSE implying that $stmt->execute(); is equivalent to FALSE->execute(); generating the error.

  • @Augustovasques then what should be changed in my code to prevent this error? could help me?

  • 1

    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.

  • With the information presented in the question it is impossible to determine a solution.

  • @Augustovasques I will try to edit the question and try to clarify it better! very obg for your help

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.