How can I connect to MySQL on a WAMP server?

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:wampwwwphp_sandboxindex.php on line 2

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

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:wampwwwphp_sandboxindex.php on line 2

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Change localhost:8080 to localhost:3306.

Method 2

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

Method 3

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x