php - MySQL访问超时错误

标签 php mysql

好的。我是 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/

相关文章:

php - 如何检查 Opencart 3 中最后执行的查询

php - 为什么我的 jQuery 函数没有按要求更改我的类?

php - MySQL 3表连接user_id,没有得到NULL值,而是重复的条目

MySQL - 计数没有返回我正在寻找的值

php - 如何在 php mysql 博客中插入图像并在确切位置显示它们

PHP 在 Windows 机器上安装 SSH2

mysql - 如何将mysql语句转换为为值添加特定数字

mysql - 如何抑制mysql中的插入

php - 我想使用 find_in_set 连接两个表

sql - mySQL返回每个类别的前5名