【问题标题】:not exist in a attribute属性中不存在
【发布时间】:2011-12-04 11:59:32
【问题描述】:

我做一个 sql 查询来检查一行是否存在......如果有我做的元组 INSERT INTO 设置 else UPDATE。 UserID 是主键。我想尝试直接在 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.'
  ';

【问题讨论】:

标签: php mysql database phpmyadmin


【解决方案1】:

是的,有一种方法可以使用单个查询。看看On duplicate key update

【讨论】:

    【解决方案2】:

    查看REPLACE mysql 语句。

    【讨论】:

      猜你喜欢
      • 2019-05-04
      • 1970-01-01
      • 2013-10-10
      • 2020-12-31
      • 1970-01-01
      • 2021-09-04
      • 2020-04-09
      • 1970-01-01
      • 2015-04-29
      相关资源
      最近更新 更多