目前我正在更新我的不同表格
$q = $dbc -> prepare("UPDATE boardposts SET lastPosterID = ?, postOrder = NOW() WHERE postID = ?");
$q -> execute(array($user['id'], $_GET['view']));
$q = $dbc -> prepare("UPDATE accounts SET msgBoardPosts = msgBoardPosts+1 WHERE id = ?");
$q -> execute(array($user['id']));
是否可以将这些更新放在一个查询中?
答案 0 :(得分:0)
是的,有可能,像:
UPDATE boardposts AS bs
left join accounts AS a on bs.AccountId = bs.lastPosterId
set bs.lastPosterId = ?, bs.postOrder = NOW(),
a.msgBoardPosts = msBoardPosts + 1
WHERE bs.postId = ?,
a.id = ?
我现在没有两个表的结构,但这是基本的想法,请参阅UPdate
的语法:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET .... table_references子句列出了连接中涉及的表。其语法描述为JOIN Syntax。