2017-04-30 41 views
1

我在我的實時web服務器上得到這個錯誤,但沒有在本地主機上測試。所以代碼不可能是罪魁禍首。PHP 7未捕獲的錯誤:調用未定義的方法mysqli_stmt :: get_result()與mysqlnd安裝

據我所知,有這個問題的解決方法,但我想知道爲什麼我用mysqlnd模塊安裝體驗它在PHP 7.0.18

enter image description here

這是我DBController類。我調用query()函數時發生該錯誤。

class DBController 
{ 
private $db; 

private $servername = "localhost"; 
private $username = "hidden"; 
private $password = "hidden"; 
private $database = "hidden"; 

function __construct(){ 
    $this->db = new mysqli($this->servername, $this->username, $this->password); 
    $this->db->select_db($this->database); 
} 

function db(){ 
    return $this->db; 
} 

private function query($sql){ 
    $sql = $this->db->prepare($sql); 
    $sql->execute(); 
    return $sql->get_result(); 
} 

function close(){ 
    $this->db->close(); 
} 
} 
+0

錯誤的實例?我們不知道,因爲你不分享你的代碼 –

+0

我更新了代碼問題。 – Organic

+0

[Call to undefined method mysqli \ _stmt :: get \ _result()AND mysqlnd installed]可能的重複(http://stackoverflow.com/questions/31005451/call-to-undefined-method-mysqli-stmtget-result-和mysqlnd安裝) – julekgwa

回答

0

事實證明,我的主機提供商錯誤地配置了PHP 7(因此沒有正確支持MySQLi)。他們後來把我搬到了一臺可以工作的新服務器上。感謝你的幫助。

1

一切都在Overview of MySQL Native Driver文檔頁面上php.net第一段解釋說:

What it is not

Although MySQL Native Driver is written as a PHP extension, it is important to note that it does not provide a new API to the PHP programmer. The programmer APIs for MySQL database connectivity are provided by the MySQL extension, mysqli and PDO MYSQL. These extensions can now use the services of MySQL Native Driver to communicate with the MySQL Server. Therefore, you should not think of MySQL Native Driver as an API.

用簡單的英語,MySQL的本機驅動程序(mysqlnd)是不夠的PHP代碼中使用MySQL 。您還需要提供API的擴展之一:MySQLiPDO MySQL

您發佈的代碼顯示您正在使用MySQLi與MySQL一起工作。它還需要安裝/啓用mysqli extension才能工作。

相關問題