MySQL PHP在具有varchar值的重复键上插入更新

时间:2019-06-11 10:04:58

标签: php mysql sql mysqli

这是我的有效代码:

$stmt = $mysqli->prepare("INSERT INTO a (b1, b2, b3, b4) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE b3 = b3 + 1;");
$arr = explode(',', $query); 
$stmt->bind_param("ssss",$arr[0],$arr[1],$arr[2],$arr[3]);
$stmt->execute();             
$stmt->close();

我需要增量更新b3(工作正常,它是int值),并另外向b4中插入一个新值(它是varchar)。这不起作用:

$stmt = $mysqli->prepare("INSERT INTO a (b1, b2, b3, b4) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE b3 = b3 + 1, b4 = VALUES(b4);");

我的密钥是b1和b2

0 个答案:

没有答案