我收到以下錯誤信息:Fatal error: Call to a member function prepare() on a non-object in <file location>
PHP:調用一個成員函數準備()一個非對象在
代碼:
$obj = new MySQLi();
$mysqli = $obj->connect();
/* Create a prepared statement */
if($stmt = $mysqli -> prepare(...)) { <--- error line
....more code
}
class MySQLi {
public $mysqli;
public function connect() {
$this->mysqli = new mysqli('localhost', 'root', '', 'icu');
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
mysqli_set_charset($this->mysqli, "utf8");
return $this->mysqli;
}
public function con_close(){
mysqli_close($con);
}
}
'$ obj-> connect'沒有一個'mysqli'對象(很可能是由於連接失敗)返回。 'var_dump($ mysqli)'會告訴你這個。 – h2ooooooo
@vascowhite那些線程沒有幫助我,我環顧四周。 –
@KarlMorrison做'var_dump($ mysqli)'。結果是什麼?正如h2o所說的 –