所以我必須使用預先準備的語句,否則會出現其他錯誤。php + sqllite3:錯誤通過預先綁定的更新綁定,當使用IS NULL/IS NOT NULL時
我不知道爲什麼,但它是不可能在同一時間像這樣準備兩個更新語句:
$sql_update_users =<<<EOF
UPDATE users SET username = :username, full_name = :full_name, is_private = :is_private , is_following = 3 , updated_on = :time WHERE user_id = :usernameId;
UPDATE users SET following_on = IfNull(following_on, :time) WHERE user_id = :usernameId;
EOF;
//Datei für update preparen
$smt2 = $db->prepare($sql_update_users);
//bindings...
//execute...
^是行不通的.... :(
所以我不得不sepperate他們:
//preper update
$smt2 = $db->prepare("UPDATE users SET following_on = :time WHERE user_id = :usernameId, following_on IS NULL");
$smt2->bindParam(':usernameId', $usernameId);
$smt2->bindParam(':time', $time);
$smt2->execute();
^這將拋出一個錯誤,我已經是「AND」替換爲「」因爲,這也是一個問題
。調用一個成員函數bindParam()布爾
然而,這個工程:
$smt2 = $db->prepare("UPDATE users SET following_on = IfNull(following_on, :time) WHERE user_id = :usernameId");
^這工作。 問題是,現在我必須更新一列,如果有多個entrys行NULL和NOT NULL。而且,由於我在使用「IS NULL」和「IS NOT NULL」時遇到錯誤,我不知道該怎麼做。
EDIT1
所以我記得知道,爲什麼 「和」 將無法正常工作。所以這條線是不行的(沒有錯誤,只是什麼都不做):
UPDATE users SET was_follower = :sync_id AND unfollowed_me_on = :time
這一行工作:
UPDATE users SET was_follower = :sync_id, unfollowed_me_on = :time
所以我需要一個解決方案,使「AND」的工作,或解決方案中使用IS NULL和IS NOT NULL用 「」
當出現錯誤時'prepare'返回'false'。錯誤是逗號。爲什麼你刪除了AND? –
@CL。我記得爲什麼「AND」不起作用。請看我的EDIT1 :) – aragonthebest