不存在于属性中
我执行一个 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.'
';
I do a sql query that checks if a row is present ... if there is the tuple I do INSERT INTO Setting else UPDATE. UserID is the primary key. I wanted to try to do it directly in a single query in php ... is it possible? I can somehow use the command not exist?
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.'
';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,有一种方法可以使用单个查询。查看关于重复密钥更新
Yes, there is a way with a single query. Take a look at On duplicate key update
查看
REPLACE
mysql 语句。Check out the
REPLACE
mysql statement.