简体   繁体   中英

faster way to grab previous data before update query?

I am about to run a mysql update query to update information in the database. My goal is to grab the previous data before it is updated and store it in a variable before it get's updated.

Is there a faster way to do it without performing 2 queries?

//grab previous time
$grab_previous_time = $dbg->prepare("SELECT timestamp FROM form WHERE id = :id");
$grab_previous_time->(array(':id' => $id));

$previous_time = $grab_previous_time->fetchColumn();
$previous_time = $previous_time['timestamp'];

//Update data
$update_form = $dbh->prepare("UPDATE `form` SET `timestamp` = :time WHERE id = :id");
$update_form->execute(array(':time' => $time, ':id' => $id));

@Dagon指出我的查询没有什么不寻常的,速度不应该与我的工作有关。

不,唯一的解决方案是您描述的解决方案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM