gpt4 book ai didi

php - fatal error : Call to a member function close() on a non-object. MySQLi 问题

转载 作者:可可西里 更新时间:2023-11-01 00:24:33 27 4
gpt4 key购买 nike

当我上传到实时服务器时出现以下错误。它在本地主机上工作正常,我认为这很奇怪。

Fatal error: Call to a member function close() on a non-object....

它引用的行

$stmt->close();

与数据库的连接

$connection=new mysqli($MYSQL_HOST,$MYSQL_USER,$MYSQL_PASS,$DB)or die(mysqli_error($connection));

类本身。

function getTimes(){ //this method just pulls the results of the query and returns them as an array
global $connection;
$route = $this->route;
$station = $this->station;
$day = $this->day;

// create a prepared statement
if ($stmt = $connection->prepare("select time from timetable where route=? and day=? and station=?")) {
$stmt->bind_param("sss", $route, $day, $station); // bind parameters for markers
$stmt->execute(); //execute query
$stmt->bind_result($col1); //bind result variables
while ($stmt->fetch()){
$results[]=$col1;
}
}
$stmt->close();//close statement
return $results;
}

最佳答案

您应该将 $stmt 放入您的 if 子句中。有可能 if (false) and still get to your $stmt->close();

关于php - fatal error : Call to a member function close() on a non-object. MySQLi 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9722159/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com