好的。我是 PHP 和 MySQL 的新手,并且遇到了问题。我有一个网站,edlineplus.x10host.com。我想做的是给定 IP 地址、用户名和密码...检查 IP 是否在数据库“auto_login”中 - 如果是,则编辑关联的用户名和密码,如果不是,则添加一个新行IP 及其数据。当我从我的计算机访问该站点时,一切正常,但是当我尝试从另一台计算机访问该站点时...加载时间很长,甚至给出错误:“ fatal error :最大执行时间为 30 秒超出行 [在下面代码中的第 4 行和第 7 行之间交替]”。我不明白这是为什么。作为引用,我使用 x10hosting.com 来托管网站,他们有一项政策“免费托管帐户不允许远程访问”(我所拥有的)。但是,是否只有当我从远程服务器上执行某些操作时才适用“远程访问”……我正在做的是将用户在我的网站上输入的数据发送到处理它的 php 文件。另外,“远程访问”问题是否会阻止我从另一台计算机连接到数据库?但没有连接到数据库本身。任何有关如何修复的帮助都会很棒......我在谷歌上搜索了很多如何解决的问题,但我不知道该怎么做。
$results = mysqli_fetch_assoc(mysqli_query($connection, "SELECT `Identification Number`, `IP Address`, `Username`, `Password` FROM `subscribed_users` ORDER BY `Identification Number`"));
$ip_address_found = false;
while ($results) {
$temp_identification_number = $results['Identification Number'];
$temp_ip_address = $results['IP Address'];
$temp_username = $results['Username'];
$temp_password = $results['Password'];
if ($ip_address == $temp_ip_address) {
$ip_address_found = true;
$protected_username = mysqli_real_escape_string($username);
$protected_password = mysqli_real_escape_string($password);
mysqli_query($connection, "UPDATE `subscribed_users` SET `Username` = '$protected_username', `Password` = '$protected_password' WHERE `subscribed_users`.`Identification Number` = $temp_identification_number;");
break;
}
}
if (!$ip_address_found) {
$protected_username = mysqli_real_escape_string($username);
$protected_password = mysqli_real_escape_string($password);
mysqli_query($connection, "INSERT INTO `subscribed_users` (`Identification Number`, `IP Address`, `Username`, `Password`) VALUES (NULL, '$ip_address', '$protected_username', '$protected_password');");
}
mysqli_close($connection);
最佳答案
首先,您应该分隔查询,如下所示:
$query = mysqli_query($connection, "SELECT `Identification Number`, `IP Address`, `Username`, `Password` FROM `subscribed_users` ORDER BY `Identification Number`");
然后更改您的 while
循环:
while ($results = mysqli_fetch_assoc($query))
mysqli_fetch_assoc()
函数一次仅获取一行。所以本质上你无限期地循环同一行,导致你的错误。
关于php - MySQL访问超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254693/