How can I connect to MySQL on a WAMP server?

☆樱花仙子☆ 提交于 2019-11-29 07:19:27

问题


This might be ridiculously easy for you but I've been struggling with this for an hour... :(

<?php
$connect = mysql_connect("localhost:8080", "root", "mypassword");
echo($connect);?>

This is the code that I'm trying to run - you can see that I'm using 8080 as my port number and, of course, I have HTML codes as well.

However, it gives me the following error messages whenever I try to open the PHP file:

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2

Warning: mysql_connect() [function.mysql-connect]: Error while reading greeting packet. PID=4932 in C:\wamp\www\php_sandbox\index.php on line 2

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2

I don't know... what's wrong with this? Is it because of the port number?


回答1:


Change localhost:8080 to localhost:3306.




回答2:


Try opening Port 3306, and using that in the connection string not 8080.




回答3:


Just Change the Connection mysql string to 127.0.0.1 and it will work



来源:https://stackoverflow.com/questions/2459006/how-can-i-connect-to-mysql-on-a-wamp-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!