一个更新查询所有更新 [英] One Update query for all updates

查看:72
本文介绍了一个更新查询所有更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的sql查询,它们正在更新同一表中的值.我想将这两个查询嵌入到一个中,但我无法做到这一点.请让我知道我该怎么做,谢谢:

Following are my sql queries that are updating values in same table. I want to embed these two query in one and i was unable to do that. Kindly let me know how can i do so , Thanks:

$SQL1 = "UPDATE table1  SET gender='$sex', dob = '$dob', reg_date ='$reg_date'
    WHERE id = '$id'"

$SQL2 = "UPDATE table1 a CROSS JOIN lookup b
 SET    a.ADRES = REPLACE(a.ADRES, b.`WRONG`, b.`RIGHT`)
 WHERE  a.ADRES LIKE CONCAT('%', b.`WRONG`, '%')"

推荐答案

UPDATE  table1 a CROSS JOIN lookup b
 SET    a.ADRES = REPLACE(a.ADRES, b.`WRONG`, b.`RIGHT`),
        gender='$sex', 
        dob = '$dob', 
        reg_date ='$reg_date'
 WHERE  a.ADRES LIKE CONCAT('%', b.`WRONG`, '%') OR 
        id = '$id'

该查询容易受到SQL Injection的攻击,请参阅下面的文章以了解如何进行保护,

the query is vulnerable with SQL Injection, please see the article below to lear how to protect from it,

这篇关于一个更新查询所有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆