【发布时间】:2016-10-01 22:15:25
【问题描述】:
所以我必须使用prepared statement,否则会出现其他错误。
我不知道为什么,但不可能像这样同时准备两个更新语句:
$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...
^不会工作.... :(
所以我不得不将它们分开:
//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");
^这行得通。 问题是,如果行 NULL 和 NOT NULL 中有多个条目,现在我必须更新一列。而且由于我在使用“IS NULL”和“IS NOT NULL”时遇到错误,我不知道该怎么办。
EDIT1
所以我记得知道,为什么“AND”不起作用。所以这条线不起作用(没有错误,什么都不做):
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 :)