我可以在localhost中正确连接MySQL。我使用FTP将PHP文件发送到其他主机,然后更改文件中的其他IP,它无法连接MySQL。我应该先连接FTP然后再连接MySQL吗?我该如何解决?
<?php
$con = mysqli_connect('otherhost.ip', 'username', 'password', 'dbname');
if (mysqli_connect_errno()) {
echo "1: Connection failed";
exit();
}
$query = "SELECT * FROM rank ORDER BY score desc limit 100";
$result = $con->query($query);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
} else {
echo "0";
}
$arr = json_encode($rows, JSON_UNESCAPED_UNICODE);
echo "{".'"allRank"'.":".$arr."}";
有单独 PHP
函数将其连接到FTP
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$username = "Your FTP username";
$password = "Your FTP password";
$ftp_conn = ftp_connect($ftp_server);
$login = ftp_login($ftp_conn, $username, $password);