"Call to undefined method mysqli_result :: fetchAll ()" in PDO [closed]

-1

The following code has an undefined method error on the line:

  

$result = ($exec!==false)?$exec->fetchAll(PDO::FETCH_ASSOC):$exec;

public function getConnection(){
            global $conn;
            $this->conn = $conn;
            if (!is_object($this->conn)) {
                $this->conn = parent::connect();
            }
        }

        public function select($qry){
            self::getConnection();
            $result = false;
            try{
                $exec = parent::execQuery($qry,$this->conn);
            }catch (PDOException $e){
                die($e->getMessage());
            }
            $result = ($exec!==false)?$exec->fetchAll(PDO::FETCH_ASSOC):$exec;
            return $result;
        }
  

UPDATE:

     

1.0 - Below is the execQuery () function that is in parent class connect

public function execQuery($qry,$con){
        $exec = $con->query($qry);

        if($exec === false){
            //ob_clean();
            throw new Exception($qry."<br>".$con->error);
        }else{
            return $exec;
        }
    }
  

UPDATE:

     

1.1 - Below is print_r($this->conn)

mysqli Object ( [affected_rows] => 0 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 0 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.5-10.1.9-MariaDB [server_version] => 50505 [stat] => Uptime: 235 Threads: 1 Questions: 10 Slow queries: 0 Opens: 1 Flush tables: 1 Open tables: 12 Queries per second avg: 0.042 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 9 [warning_count] => 0 ) mysqli Object ( [affected_rows] => -1 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 0 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.5-10.1.9-MariaDB [server_version] => 50505 [stat] => Uptime: 235 Threads: 1 Questions: 10 Slow queries: 0 Opens: 1 Flush tables: 1 Open tables: 12 Queries per second avg: 0.042 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 9 [warning_count] => 0 ) 

Why this error happens?

  • PDO is enabled
  • PHP Version 5.6.15
asked by anonymous 14.03.2016 / 21:51

1 answer

1

Resolved by setting a single connection type to:

$con = new PDO('mysql:host='.self::DB_HOST.';dbname='.self::DB_NOME, self::DB_USER, self::DB_PASS); 
    
15.03.2016 / 20:22