所以我使用以下mysqli代码创建了这个PHP文件,每30分钟在我的数据库上运行一些脚本。我可以通过输入网址在网站上打开这个页面并运行正常,但是当我在网络解决方案cron选项卡上将其设置为cron作业时,它每次都会失败。我收到以下错误消息,我似乎无法找到我在这里寻找其他问题的答案。服务器名称是正确的,因为如果我手动运行它,它会正常运行。
无法连接到MySQL:无法连接到mysql服务器'mysqlcluster7'
<?php
$con=mysqli_connect("mysqlcluster7","test","xxxxxx","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
mysqli_query($con,"INSERT IGNORE INTO tblvenueimg (v_location) SELECT location FROM events GROUP BY location");
mysqli_query($con,"UPDATE events INNER JOIN tblvenueimg ON events.location = tblvenueimg.v_location SET events.venueimg = tblvenueimg.v_locimage");
mysqli_query($con,"INSERT INTO tblmusic (soundcloudprof, name, username) SELECT t.musicprof, t.musicprof, t.musicprof FROM (SELECT musicprof
from events where musicprof <> ' ' group by musicprof) as t
ON DUPLICATE KEY UPDATE soundcloudprof = t.musicprof, name = t.musicprof, username = t.musicprof");
mysqli_query($con,"UPDATE events INNER JOIN tblmusicfeatured ON events.user_name = tblmusicfeatured.username SET events.musicprof = tblmusicfeatured.soundcloudprof");
mysqli_query($con,"UPDATE events SET trending ='2' WHERE location LIKE '%boston%'");
mysqli_query($con,"UPDATE events SET trending ='2' WHERE location LIKE '%allston%'");
mysqli_query($con,"UPDATE events SET trending ='2' WHERE location LIKE '%cambridge%'");
mysqli_query($con,"UPDATE events INNER JOIN tblfeatureddj ON events.id_user = tblfeatureddj.id_user SET trending ='3'");
mysqli_query($con,"UPDATE events SET trending ='4' WHERE profimg LIKE '%017.jpg%'");
mysqli_close($con);
?>