更新后获取以前的值

编程入门 行业动态 更新时间:2024-10-21 16:38:42
本文介绍了更新后获取以前的值-MySql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含ID和名称的表

I have a table which includes id and name

--- ----- id name --- ----- 1 pete

我的情况如下

$sql = "SELECT name FROM table_name WHERE id=1"; previous name - '' current name - pete

现在我要更新

$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

推荐答案

您可以通过在触发器.

尽管,我看到您将帖子标记为php,我想您想在php中获取旧值,并且要执行此操作,您必须在UPDATE之前执行SELECT才能获得旧名称,以及在UPDATE之后的另一个SELECT以获取新名称.

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.

更多推荐

更新后获取以前的值

本文发布于:2023-10-28 19:27:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!