【问题标题】:Infinite Loading When Trying to Connect Into MySQL尝试连接到 MySQL 时无限加载
【发布时间】:2016-11-20 01:29:02
【问题描述】:

我在连接到 XAMPP 中的 mysql 数据库时遇到问题。加载这段 php 代码总是需要时间。可能是什么问题?

            <?php
            session_start();

            //redirect function
            function returnheader($location){
                $returnheader = header("location: $location");
                return $returnheader;
            }

            $connection = mysqli_connect("localhost:85","root","") OR die(mysqli_error());
            $db_select = mysqli_select_db("pts",$connection) OR die(mysqli_error());

            $errors = array();

            if(isset($_POST["iebugaround"])){

            //lets fetch posted details
            $uname = trim(htmlentities($_POST['uname']));
            $passw = trim(htmlentities($_POST['psw']));

            //check username is present
            if(empty($uname)){

                //let echo error message
                $errors[] = "Please input a username";

            }

            //check password was present
            if(empty($passw)){

                //let echo error message
                $errors[] = "Please input a password";

            }

            if(!$errors){

                //encrypt the password
                $passw = sha1($passw);
                $salt = md5("userlogin");
                $pepper = "ptsbtr";

                $passencrypt = $salt . $passw . $pepper;

                //find out if user and password are present
                $query = "SELECT * FROM users WHERE username='".mysqli_real_escape_string($uname)."' AND password='".mysqli_real_escape_string($passencrypt)."'";
                $result = mysqli_query($query) OR die(mysqli_error());

                $result_num = mysqli_num_rows($result);

                if($result_num > 0){

                    while($row = mysqli_fetch_array($result)){

                        $idsess = stripslashes($row["id"]);
                        $firstnamesess = stripslashes($row["firstname"]);
                        $username = stripslashes($row["username"]);

                        $_SESSION["SESS_USERID"] = $idsess;
                        $_SESSION["SESS_USERFIRSTNAME"] = $firstnamesess;
                        $_SESSION["SESS_USERNAME"] = $username;

                        setcookie("userloggedin", $username);
                        setcookie("userloggedin", $username, time()+43200); // expires in 1 hour

                        //success lets login to page
                        returnheader("users-area.php");

                    }

                } else {

                    //tell there is no username etc
                    $errors[] = "Your username or password are incorrect";

                }

            }


            } else {

            $uname = "";

            }

            ?>

这是加载几分钟后的错误。

Warning: mysql_connect(): MySQL server has gone away in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10

Warning: mysql_connect(): Error while reading greeting packet. PID=6940 in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10

Warning: mysql_connect(): MySQL server has gone away in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\peopletrackingsystem\login.php on line 10

(背景故事:我的 Apache 也遇到了 localhost/127.0.0.1 的问题。每次我尝试仅使用 localhost 访问它时它只会出现空白页面。所以我每次尝试访问它时总是放置端口。我已经删除了 hosts 文件中所有不必要的端口。我已经更改了 httpd.conf 的侦听端口和服务器名称,其中包含端口)

【问题讨论】:

  • 既然是 XAMPP,你确定 MySQL 没有在 3306 端口上运行吗?内置的 phpMyAdmin 是否有效?
  • 是的,MySQL 的端口是 3306,phpMyAdmin 也可以正常加载。
  • 好的,只是想知道为什么你的主机名是localhost:85

标签: mysql apache xampp


【解决方案1】:

不能在“localhost:85”中添加端口,试试这样:

 $connection = mysqli_connect("localhost","root","") OR die(mysqli_error());

【讨论】:

  • 谢谢。我删除了自定义 xampp 端口并将其设置为默认端口(80)并修复了一切。
猜你喜欢
  • 2021-11-27
  • 2020-10-24
  • 2020-09-21
  • 1970-01-01
  • 1970-01-01
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多