Mysql: auto update date in select string
I am working on PHP / MySQL and I am trying to make it automatically update my time if a row is selected.
Here is the SQL I am using and I am trying to make it automatically update at the same time without adding UPDATE
:
MySQL table (I want to Last_Selected_Time
update on row selection)
CREATE TABLE IF NOT EXISTS `accounts` (
`Username` varchar(255) NOT NULL,
`Last_Selected_Time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
primary key(Username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
PHP Code Segments:
$sql = "SELECT * FROM accounts where Username = 'test'";
$result = $conn->query($sql);
+3
source to share
1 answer
This sounds like a trigger that you should use, but unfortunately you cannot do that for a selection. You can do it with a stored procedure instead: check this answer: can I fire a trigger for a select statement in mysql?
0
source to share