After reinstalling the open server, the execute() php7 method stopped working.

request:

 $sql = 'SELECT count(*) as count FROM records WHERE hiddenRecord = 0'; 

The array entering the SqlExecute() function is empty.

processing function:

 private function SqlExecute($sql = '', $array = []) { if($sql != '') { $Query = $this->Connect(); if($Query != null) { $Query->prepare($sql); foreach($array as $key => $str) { if(is_numeric($str)) { $Query->bindParam($key, $array[$key], PDO::PARAM_INT); } elseif(is_string($str)) { $Query->bindParam($key, $array[$key], PDO::PARAM_STR); } } $Query->execute(); if($Query->rowCount() > 0) { return [ 'count' => $Query->rowCount(), 'lastId' => $this->Connect()->lastInsertId(), 'result' => $Query, 'status' => true, ]; } else { return [ 'count' => 0, 'lastId' => 0, 'result' => '', 'status' => false, ]; } } } return [ 'count' => 0, 'status' => false, ]; } // Соединение. private function Connect() { static $ini__li; if($ini__li === null) { try { $ini__li = new PDO( $this->base, $this->user, $this->pass ); $ini__li->exec('SET NAMES UTF8'); } catch(PDOException $e) { $ini__li = null; } } return $ini__li; } 

Displayed error

Fatal error: Uncaught Error: Call to undefined method PDO :: execute ()

  • connection has exec statement has execute . here you have an object from the first, and a method from the second - teran
  • @teran like that ..... - Dmitry

1 answer 1

 $Query = $this->Connect(); 

Here you create a PDO object.

further prepare the expression

 $Query->prepare($sql); 

This expression returns an instance of PDOStatement .
Next, you try to attach the bindParam and execute methods to the PDO object, although you have to do something like

 $stmt = $Query->prepare($sql); $stmt->bindParam(...) $stmt->execute(); 
  • Why the hell did this work before? - Dmitriy