在php中更新自动Mysql值

在php中更新自动Mysql值,php,Php,您好,我想在设定的时间自动更新MySQL表,就像我想在5:30更新表一样,我的数据库中有一些值要在设定的时间自动更新。在PHP中 $date = date('H:i:s'); if($date == "11:26:00") // 17:30:00 is equal to 5:30 but in 24 system { $sql1 = "SELECT * FROM No where id='1'"; $result1 = mysqli_query($mysqli,$sql1) o

您好,我想在设定的时间自动更新MySQL表,就像我想在5:30更新表一样,我的数据库中有一些值要在设定的时间自动更新。在
PHP中

$date = date('H:i:s');
if($date == "11:26:00") // 17:30:00 is equal to 5:30 but in 24 system 
{
    $sql1 = "SELECT * FROM No where id='1'";
    $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
    while($row= mysqli_fetch_assoc($result1))
    {
    $Foo= $row['foo'];
    }
    $sql2 = "UPDATE No SET id='2',foo='$foo' where id='2'";
    $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());

}

只要撒谎Ashish说你可以使用CRON,如果你想你也许可以使用这个,我以前没有用过,试试吧。这段代码只工作一次,所以你必须找出一个循环,因为时间每秒钟都会改变

注意:检查第二个代码

<?php 
    // Database connect

    $date = date('H:i:s'); // Set the time to hours and minutes and seconds format  
    // you can echo $date to check how it looks but it will be something like this : 07:21:48

    if($date == "17:30:00") // 17:30:00 is equal to 5:30 but in 24 system 
    {
        // You can type your code here . 

    }

 ?>

第二个代码:

<?php

 // Remember to connect to your database    

$date1 = date_create("00:00");
$date2 = date_create("23:59");
while($date1<=$date2)
{
    date_add($date1,date_interval_create_from_date_string("1 sec"));
    $a = date_format($date1,"H-i-s");
    if($a =='17:30:00')
    {
            $sql1 = "SELECT * FROM No where id='1'";
            $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
            $row= mysqli_fetch_assoc($result1)
                {
                    $Foo= $row['foo'];
                    $sql2 = "UPDATE No SET id='2',foo='$foo' where id='2'";
                    $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
                }
            die;
       }
    else
      {
         // you can type anything here , you can end the process by typing die; or anything you want 
      }

}



?>

你可以使用CRON,如果它只等于11:26,它就可以工作,所以你必须设置一个循环,这样它可以抛出一整天,并检查日期是否等于该时间不起作用,我正在使用这样的循环foreach($date as$dates),如果($dates==“11:26:00”)@汉克斯:好的,我正在更新我的答案给我点时间让我想想。(时间循环)@hanks检查新答案并检查第二个代码。如果上述代码有效,那么您所要做的就是将$date1更改为您当前的时间server@hanks刚刚编辑了答案,编辑了mysqli部分,想问一下,出现了什么错误?