2016-10-01 37 views
0

所以我必须使用预先准备的语句,否则会出现其他错误。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用 “”

+0

当出现错误时'prepare'返回'false'。错误是逗号。为什么你删除了AND? –

+0

@CL。我记得为什么“AND”不起作用。请看我的EDIT1 :) – aragonthebest

回答

0
UPDATE users SET following_on = :time WHERE user_id = :usernameId, following_on IS NULL 

在此查询,逗号必须是AND。

UPDATE users SET was_follower = :sync_id AND unfollowed_me_on = :time 

在此查询中,并且必须是一个逗号(,如果你想改变unfollowed_me_on)或WHERE(如果unfollowed_me_on决定哪些行被更新)。

+0

非常感谢你,我不知道为什么,但它的工作知道:D – aragonthebest