我执行一个sql查询来检查是否存在一行...如果存在我执行INSERT INTO设置的元组,否则UPDATE。用户 ID 是主键。我想尝试直接在 php 中的单个查询中执行此操作...可能吗?我可以以某种方式使用不存在的命令吗?
enter code here
$query = 'INSERT INTO Settings SET
userID = '.$uid.',
visibility = -1,
notify_icon = true,
notify_connect_friend = true,
notify_near_friend = true,
ringer = true,
vibration = true
';
$query = 'UPDATE Settings SET
visibility = '.$visibility.',
notify_icon = '.$notify_icon.',
notify_connect_friend = '.$notify_connect_friend.',
notify_near_friend = '.$notify_near_friend.',
ringer = '.$ringer.',
vibration = '.$vibration.'
WHERE
userID = '.$uid.'
';
最佳答案
是的,有一种方法可以使用单个查询。看看On duplicate key update
关于php - 不存在于属性中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8375129/