これは私の最初の投稿ですので、私には簡単に行く^ _^致命的なエラー:非オブジェクトのメンバ関数close()を呼び出します。 MySQLiの問題
私はライブサーバーにアップロードしたときに次のエラーが発生しています。それは私が奇妙だと思ったlocalhost上で動作します。どんな助けでも大歓迎です。
Fatal error: Call to a member function close() on a non-object....
が
$stmt->close();
DB
$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;
}
何らかの理由で$ connection-> prepare()が失敗したようです。 falseを返した場合、$ stmtはfalseで、期待通りのmysqliオブジェクトではありません。 – Crashspeeder
あなたの$接続もnullで、あなたがそれをチェックしていない可能性もあります。しかし、それは現時点であなたのエラーではありません – Churk
@Churkこれは、致命的なエラーになります:非オブジェクト上のメンバ関数prepare()を呼び出します。どちらの方法でも、私は接続としてパラメータとして渡す必要があることに同意します: 'function getTimes(mysqli $ connection){}' – cmbuckley