mysql updata 前面得到的值,更新后获取以前的值-MySql

I have a table which includes id and name

--- -----

id name

--- -----

1 pete

My scenarios looks like this

$sql = "SELECT name FROM table_name WHERE id=1";

previous name - ''

current name - pete

Now i'l update

$sql = "UPDATE table_name SET name='dave' WHERE id=1";

previous name - pete

updated name - dave

$sql = "UPDATE table_name SET name='Alan' WHERE id=1";

previous name - dave

updated name - Alan

So after i update this table, i wanted to fetch previous record which was present in it. In my example i should get previous name as well as updated name. How to achieve this

解决方案

You can do that by using the OLD and NEW keywords on a trigger on your table.

Although, i see that you tagged your post as php and I guess you want to get the old value in php, and to do this, you have to do a SELECT before the UPDATE to get the old name, and another SELECT after the UPDATE to get the new name.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值