PHP无法连接到MySql(MySqli) [英] PHP cant connect to MySql (MySqli)
问题描述
我正在尝试使用php和mysqli简单地连接到本地主机上的MySQL数据库.但是我遇到了一个问题.
I'm trying to simply connect to a MySQL database on my localhost With php and mysqli. But I'm encountering a problem.
我在下面写了代码
<?php
$sql = new mysqli('127.0.0.1:777','root','Qwert12345','plot_io_db');
//echo $sql->query('Select * From players');
?>
假设所有信息都是正确的(有一个正在运行的MySQL服务器,并且其中包含名称为'plot_io_db'且用户名和密码正确的数据库),脚本返回结果仍然需要一段时间,然后它返回以下结果
Assuming that all the information is correct (there is a MySQL server running and it includes a database with the name 'plot_io_db' and username and the password are correct), it still takes ages for the script to return results and it returns the following result
Warning: mysqli::__construct(): MySQL server has gone away in C:\xampp\htdocs\test\default.php on line 2
Warning: mysqli::__construct(): Error while reading greeting packet. PID=11092 in C:\xampp\htdocs\test\default.php on line 2
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\test\default.php on line 2
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\test\default.php on line 2
我的问题是:为什么会发生这种情况以及如何解决这个问题.
My question is: Why does this happen and how to solve this.
P.S:我评论了第三行只是为了将结果时间控制在10分钟以内!
P.S: I commented the third line just to bring the result time below ten minutes!
推荐答案
<?php
$sql = new mysqli('127.0.0.1','root','Qwert12345','plot_io_db');
//echo $sql->query('Select * From players');
?>
它将起作用.只需从本地主机(127.0.0.1)删除端口
It will work. Just remove port from localhost (127.0.0.1)
这篇关于PHP无法连接到MySql(MySqli)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!