在XAMPP中连接到MySQL时出错 [英] Error connecting to MySQL in XAMPP
问题描述
我已经为登录页面创建了这个简单的PHP代码
I have created this simple PHP code for a login page
<head>
<title>Login Page</title>
</head>
<body>
<form method=POST>
<table>
<tr><th>UserName</th>
<td><input type=text name=user></input></td></tr>
<tr><th>Password</th>
<td><input type=password name=pass></input></td></tr>
<tr><th>Phone Number</th>
<td><input type=text name=phone></input></td></tr>
<tr><th>Email</th>
<td><input type=text name=email></input></td></tr>
<tr><th>City</th>
<td><input type=text name=city></input></td></tr>
<tr><td><input type=submit name=submit value=Submit></input></td></tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']) && !empty($_POST['user']))
{
if(preg_match("/^[a-zA-Z ]{3,40}$/",$_POST['user']))
{
if(preg_match("/^[a-zA-Z0-9]{8,20}$/",$_POST['pass']))
{
if(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
if(preg_match("/[0-9]{10}/",$_POST['phone']))
{
$username=$_POST['user'];
$password=$_POST['pass'];
$Email=$_POST['email'];
$phoneNumber=$_POST['phone'];
$con=mysqli_connect("localhost:8080","root","","user");
mysqli_query($con,"insert into user values('$username','$Email','$phoneNumber','$city')");
}
else
{
echo "Invalid Phone number";
}
}
else
{
echo "Invalid Email";
}
}
else
{
echo "Invalid Phone number";
}
}
else
{
echo "Invalid user";
}
}
?>
每当我运行此脚本并尝试将值插入表中时,都会花费大量时间并引发以下错误/警告.我尚未更改用户名和密码,并且我相信默认情况下它是root和空白.
Whenever i run this script and try to insert values into the tables, it takes a lot of time and throws the following error/Warning. I have not changed the username and password and i believe by default it is root and blank.
警告:mysqli_connect():MySQL服务器已在第39行的C:\ xampp \ htdocs \ home.php中消失
Warning: mysqli_connect(): MySQL server has gone away in C:\xampp\htdocs\home.php on line 39
警告:mysqli_connect():读取问候数据包时出错.第39行的C:\ xampp \ htdocs \ home.php中的PID = 4708
Warning: mysqli_connect(): Error while reading greeting packet. PID=4708 in C:\xampp\htdocs\home.php on line 39
警告:mysqli_connect():(HY000/2006):MySQL服务器已在第39行的C:\ xampp \ htdocs \ home.php中消失
Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\home.php on line 39
致命错误:第39行的C:\ xampp \ htdocs \ home.php中超过30秒的最大执行时间
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\home.php on line 39
有人可以帮我这个忙,因为我认为问题出在某些端口配置上.
Could someone help me with this as i believe that the problem lies with some of the port configuration.
感谢和问候.
推荐答案
默认情况下,使用XAMPP连接到DB不需要您指定端口.将localhost:8080
替换为localhost
By default, connecting to DB using XAMPP doesn't require you to specify the port. Replace localhost:8080
with localhost
这篇关于在XAMPP中连接到MySQL时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!