我想把每个帖子的日期改成一个更老的日期,再过一年。我的代码过去在PHP 5上运行得很好,但在PHP 7上却不行。我想知道我应该做些什么改变。我知道有些东西在PHP 7上不受欢迎,但我不确定我需要编辑哪些部分。
这是我的密码。提前感谢大家的帮助。
<?php
error_reporting(0);
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM dm_posts where post_date > \'2017-04-30\'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Post Title</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["ID"]."</td><td>".$row["id"]." ".$row["post_title"]."</td></tr>" ;
$idd = $row["ID"];
$int= rand(1388534400,1418342400);
$futuredate = date("Y-m-d H:i:s",$int);
$query1 = "UPDATE dm_posts SET post_date = \'".$futuredate."\' where post_date > \'2017-04-30\' and id = \'".$idd."\'";
$result1 = $conn->query($query1);
}
echo "</table>";
} else {
echo "All IS DONE";
}
$conn->close();
?>