我想在5秒后调用一个mysql查询

时间:2014-06-09 11:12:53

标签: php mysql

我想在5秒后调用一个mysql查询。我的代码在下面,但它不起作用请帮助我:

<?php

$connect = mysql_connect("localhost","root","");

mysql_select_db("test",$connect);

$time= date('s');

$time2 = $time+5;


if($time==$time2){
mysql_query("UPDATE table_name SET name='John'
where user_name='test'");

}

?>

2 个答案:

答案 0 :(得分:8)

使用睡眠功能:

sleep(5);
//run query

您的代码:

$connect = mysql_connect("localhost","root","");

mysql_select_db("test",$connect);

sleep(5);

mysql_query("UPDATE table_name SET name='John'
where user_name='test'");

顺便说一句,我必须注意到这听起来像是一个糟糕的主意。

答案 1 :(得分:-2)

<?php
$connect = mysql_connect("localhost","root","");
mysql_select_db("test",$connect);

sleep(5); // will halt process for 5secs
mysql_query("UPDATE table_name SET name='John' where user_name='test'");
?>