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.