PHP致命错误:在Godaddy主机上调用未定义的方法mysqli_stmt :: get_result()[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在编写一些代码来使用预处理语句获取数据。以下是我的代码

$statement = $connection->prepare("select * from products where id =?");
$statement->bind_param('d',$id);
$statement->execute();
$result = $statement->get_result();
$product_details = $result->fetch_all();

我正在使用PHP 5.6。这在我的localhost上运行正常,没有错误。当我将此文件上传到Godaddy Host时,会出错:

PHP致命错误:调用未定义的方法mysqli_stmt :: get_result()

我在互联网上搜索,但没有找到满意的结果,在stackoverflow上我发现了几个类似的问题,但没有得到解决方案。在Godddy主持人我启用mysqld扩展并运行PHP 5.6所以任何帮助

php mysql mysql-error-1064
1个回答
0
投票

您的$ statement-> execute()可能存在问题。尝试在try catch块中运行此代码,可能是您发现了一些异常。或使用if块运行此方法。

if($statement){
    $result = $statement->get_result();
} 

要么

try{
   $statement = $connection->prepare("select * from products where id =?");
   $statement->bind_param('d',$id);
   $statement->execute();
   if($statement){
     $result = $statement->get_result();
   } 
   $product_details = $result->fetch_all(); 
} catch (Exception $e) {
   echo 'Caught exception: ',  $e->getMessage(), "\n";
}
© www.soinside.com 2019 - 2024. All rights reserved.