"Call to Undefined method mysqli_result::fetchAll()" in PDO

Asked

Viewed 1,059 times

-1

The following code displays 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 - The function follows below execQuery() who is in the 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 the 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 mistake happens?

  • PDO is enabled
  • PHP Version 5.6.15
  • There’s something really wrong there, mysqli_result::fetchAll()?

  • Yeah, bro. kkkkkkk I DON’T KNOW EITHER!

  • Take a look at execQuery()

  • rray, edited..

  • In select, give a print_r on $this->conn and $exec or has variable being overwritten or some file being pulled wrong.

  • rray: mysqli_result Object ( [current_field] => 0 [field_count] => 5 [lengths] => [num_rows] => 0 [type] => 0 )

  • It’s not PDO, mysqli, there’s something wrong with your files.

  • I’ll put up the $this->Conn

  • Ta edited, rray

  • 1

    It is easier for you to locate everything that is "mysqli" in your files, and consequently find the error. Virtually all good code editors have a file search.

  • 2

    Everything is in mysqli $con = @new mysqli(self::DB_HOST, self::DB_USER, self::DB_PASS, self::DB_NOME);

  • Why does this error occur? PHP version/?

  • The PDO has the fetchAll() and Mysqli from php5.3 has the fetch_all()

  • 2

    Either it is mysqli or it is PDO... You need to choose which one to use, there is no way to mix pieces of one into the other. If you open the connection with PDO, you have to use only the functions or methods of PDO, in the same way, if opened with mysqli, you have to use only those of mysqli.

  • Bacco, that explains the confusion or the problem?

  • But they’re complaining about mysqlnd and not PDO, the mysqlnd is activated?

  • @deFreitas he was not using PDO, see the line in the comments: $con = @new mysqli(self::DB_HOST, self::DB_USER, self::DB_PASS, self::DB_NOME);

  • 1

    @Bacco is exactly what I’m saying, he said he has the PDO activated but it doesn’t make a difference because he’s using mysqlnd

Show 13 more comments

1 answer

1

Solved 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); 

Browser other questions tagged

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