仅针对特定值执行SET?

时间:2016-07-30 14:45:57

标签: php mysql

$x = 5;
$stmt = $db->prepare('UPDATE ' . $table. ' SET sort = sort + 1') ;
$stmt->execute();

如何仅针对sort列中等于或高于$x的值执行查询?

1 个答案:

答案 0 :(得分:3)

只需将其添加到where语句:

$stmt = $db->prepare('UPDATE ' . $table. ' SET sort = sort + 1 where sort >= ?') ;
$stmt->bind(1, $x)