[英]Cron job execute php file
I set my cronjob to run a php file every one minute. 我设置我的cronjob每隔一分钟运行一个php文件。 The php file access to the database to update a value in a row. php文件访问数据库以连续更新一个值。 Here is the php code 这是PHP代码
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else {
mysql_query("UPDATE tanlename SET status = 2 WHERE created < (NOW() -
INTERVAL 1 MINUTE)");
}
mysqli_close($conn);
?>
I want the code to set the status of a post to 2 after 1 minute of the its posting time. 我希望代码在其发布时间1分钟后将其状态设置为2。
The problem is in the else
here: 问题出在else
地方:
You need to change mysql_
to mysqli_
- not only is mysql_
deprecated but also because you're already using mysqli_
in $conn
. 您需要更改mysql_
到mysqli_
-不仅mysql_
过时但也因为你已经使用mysqli_
在$conn
。
Then you need to specify the connection in the mysqli_query
. 然后,您需要在mysqli_query
指定连接。
Update your old code from: 从以下位置更新旧代码:
else {
mysql_query("UPDATE tanlename SET status = 2 WHERE created < (NOW() -
INTERVAL 1 MINUTE)");
}
to this: 对此:
else {
mysqli_query($conn, "UPDATE tanlename SET status = 2 WHERE created < (NOW() - INTERVAL 1 MINUTE)");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.