Mysqli查询sysdate/now没有';在随后的执行中不会发生变化


Mysqli query sysdate/now doesn't change on subsequent executions

我有一个html页面,它每20秒用数据库中的数据更新一个图。我调用这个函数是为了在再次查询数据库之前设置一个延迟:

setTimeout(update, 20000);

这将调用函数更新:

function update() {
    $.get('getRealtimeData.php?', function(data) {
        //data is parsed and sent to the graph successfully.
    }
}

它用以下代码调用php页面:

//parameter retrieval and connection
$query = "select KiloBytesTransferred, DateTimeInitiated from Flows where DateTimeInitiated > date_add(now(), interval ? hour)";
$hours = -1; //normally populated by parameter sent to the page 
$stmt = $con -> stmt_init();
$persecond = 0;
if ($stmt -> prepare($query)) {
    $stmt -> bind_param('d', $hours);
    $stmt -> execute();
    $stmt -> bind_result($KiloBytesTransferred, $DateTimeInitiated);
    while ($stmt -> fetch()) {
        $persecond = $KiloBytesTransferred / 60;
        echo $persecond;
        echo ",";
        echo $DateTimeInitiated;
        echo ";";
    }
    $stmt -> close();
}
$con -> close();

当我在Firefox或Chrome中调试这个项目并用数据库中的结果设置警报时,它工作得很好。当我尝试在Internet Explorer中运行此项目时,数据不会更改。每次查询数据库时,返回的结果都是相同的。我通过检查DateTimeInitiated列来验证这一点。甚至几分钟后,查询返回数据,就好像查询的"now()"部分没有更改一样。

我尝试过用sysdate()代替now(),并获得了相同的结果。在其他计算机(我队友的)上运行相同的项目也会产生相同的结果。刷新页面会产生新的数据,但随后的调用不会像以前那样更改。

我正试图通过Internet Explorer中的后续调用来更改数据,因为这将是用于访问页面的主浏览器。我尝试过进行研究,但没有发现sysdate/now在完全不同的调用中不会发生变化。我是PHP和JavaScript的初学者,这是为我们Capstone类中的一个真正客户的项目准备的,所以欢迎任何建议。

尝试在URL中添加一个随机参数,以防止其缓存,例如:-

function update() {
    var rndNum = Math.round(new Date().getTime() / 1000);
    $.get('getRealtimeData.php?rand='+rndNum, function(data) 
    {
        //data is parsed and sent to the graph successfully
    }
}