Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试连接到MySQL时无限加载_Mysql_Apache_Xampp - Fatal编程技术网

尝试连接到MySQL时无限加载

尝试连接到MySQL时无限加载,mysql,apache,xampp,Mysql,Apache,Xampp,我在XAMPP中连接mysql数据库时遇到问题。加载这段php代码总是需要时间。有什么问题吗 <?php session_start(); //redirect function function returnheader($location){ $returnheader = header("location: $location");

我在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 = "";

            }

            ?>
(背景:我的Apache在localhost/127.0.0.1上也有问题。每次我尝试仅使用localhost访问它时,它只会出现空白页。因此,每次尝试访问它时,我都会放置端口。我已经删除了hosts文件中所有不必要的端口。我已经使用端口更改了httpd.conf的侦听端口和服务器名称在其中)

您不能在“localhost:85”中添加端口,请按如下方式尝试:

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

由于它是XAMPP,您确定MySQL没有在端口3306上运行吗?内置的phpMyAdmin工作吗?是的,MySQL的端口是3306,phpMyAdmin的负载也很好。好的,只是想知道为什么您的主机名是
localhost:85
谢谢。我删除了自定义的XAMPP端口,并将其设置为默认端口(80),并且一切都已修复。
 $connection = mysqli_connect("localhost","root","") OR die(mysqli_error());