我開始使用mysqli_*
功能,而不是在PHP老mysql_*
功能,和我有一個有點問題,這段代碼:的mysqli ::準備():無法獲取的MySQL
public function addUser($table, $code = false, $rows = false) {
if (!$code) {
header("Location: " . $this->authenticate());
} else {
$this->getToken($code);
}
$user = $this->getEndpoint('users/current', false, true);
$user = $user->response->user;
if (!$rows)
$rows = array(
"remote_id" => $user->id,
"firstName" => $user->first_name,
"lastName" => $user->last_name,
"photo" => $user->photo->medium,
"gender" => $user->gender == 'male' ? 1 : 2,
"email" => $user->contact->email,
);
$rows['access_token'] = $this->accessToken;
$stmt = $this->mysql->prepare("SELECT id FROM users WHERE access_token = '{$this->accessToken}'"); //line 136
$stmt->execute(); //line 137
}
代碼返回這2個錯誤:
Warning: mysqli::prepare(): Couldn't fetch MySQL in C:\Users\Grega\Server\application\inc\classes\APIConnect.php on line 136
Fatal error: Call to a member function execute() on a non-object in C:\Users\Grega\Server\application\inc\classes\APIConnect.php on line 137
'無法獲取MySQL'的原因是什麼?數據庫連接是正確的,它在其他類中起作用,並且如果我在phpMyAdmin中執行它並執行它,查詢將返回一個有效結果。另外,我的變量名爲mysql
不是mysqli
!
這是**不**使用預準備語句的方式。你沒有準備任何東西。 – PeeHaa
一個有用的鏈接:http://codular.com/php-mysqli – saji89