我一直停留在這個約30分鐘,我不知道如果IM俯瞰什麼,但我不斷收到以下錯誤(主要是意味着我的SQL無效):IF ELSE不適用於MySQL?
Fatal error: Call to a member function bind_param() on a non-object...
SQL:
IF (SELECT value FROM votes WHERE thread = ? AND owner = ?) THEN
UPDATE votes SET (value = ?) WHERE thread = ? AND owner = ?
ELSE
INSERT INTO votes (thread, owner, value) VALUES (?, ?, ?)
END IF
PHP:
$stmt = $this->database->prepare("IF (SELECT value FROM votes WHERE thread = ? AND owner = ?) THEN UPDATE votes SET (value = ?) WHERE thread = ? AND owner = ? ELSE INSERT INTO votes (thread, owner, value) VALUES (?, ?, ?) END IF");
$stmt->bind_param("dddddddd", $this->id, $userId, $value, $this->id, $userId, $this->id, $userId, $value);
$stmt->execute();
根據MySQL的文檔,我應該是正確的?
IF search_condition THEN statement_list
[ELSEIF search_condition THEN statement_list] ...
[ELSE statement_list]
END IF
您正在使用庫MySQLi或PDO(用PHP檢查)? –
@ErolKESKİNMySQLI –
@CodeCaster Nope。另一個線程正在討論如何獲取錯誤。這是關於爲什麼錯誤正在發生以及如何避開它 – Machavity