尝试连接MySQL时无限加载

时间:2016-07-17 09:29:36

标签: mysql apache xampp

我在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的监听端口和服务器名称。)

1 个答案:

答案 0 :(得分:0)

只需将“ http://”添加到“ localhost:85”,就像这样:

$connection = mysqli_connect("http://localhost:85","root","") OR die(mysqli_error());