Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

PHP cant connect to MySql (MySqli)

I'm trying to simply connect to a MySQL database on my localhost With php and mysqli. But I'm encountering a problem.

I Wrote the code below

<?php
$sql = new mysqli('127.0.0.1:777','root','Qwert12345','plot_io_db');
//echo $sql->query('Select * From players');
?>

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:xampphtdocs	estdefault.php on line 2
Warning: mysqli::__construct(): Error while reading greeting packet. PID=11092 in C:xampphtdocs	estdefault.php on line 2
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in C:xampphtdocs	estdefault.php on line 2
Fatal error: Maximum execution time of 30 seconds exceeded in C:xampphtdocs	estdefault.php on line 2

My question is: Why does this happen and how to solve this.

P.S: I commented the third line just to bring the result time below ten minutes!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<?php
$sql = new mysqli('127.0.0.1','root','Qwert12345','plot_io_db');
//echo $sql->query('Select * From players');
?>

It will work. Just remove port from localhost (127.0.0.1)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...