mysql_connect won't work

Problems with the Windows version of XAMPP, questions, comments, and anything related.

mysql_connect won't work

Postby nd00jan » 18. January 2009 00:59

I'm trying to connect to my MySQL database with the following code:
<?php
$con = mysql_connect("localhost:8080","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>

Then I get the following error:
Code: Select all
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 0 in C:\xampp\htdocs\test.php on line 2

Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\test.php on line 2


What can be wrong? It's should be pretty simple, but it's not working...

I'm running IIS on port:80 therefore I've changed apache to run on port:8080, and I can view the startpage for XAMPP and all that, and do simple code like "Hello world", but it's the connection to the database that doesn't work. In phpMyAdmin i have like this:
Code: Select all
root   127.0.0.1   No   ALL PRIVILEGES    Yes   
root   localhost   No   ALL PRIVILEGES    Yes   
root   localhost:8080   No   ALL PRIVILEGES    Yes

...so I thing I've covered both kinds of ports (80 and 8080), and in my case it's localhost:8080.

But, still not working. Does anyone have any suggestions? How can I resolve this?
nd00jan
 
Posts: 2
Joined: 18. January 2009 00:02

Re: mysql_connect won't work

Postby Izzy » 18. January 2009 01:06

What address are you typing in the address bar of your browser to load test.php?


It is the Apache web server that uses localhost on port 80 by default or when changed, as in your case, 8080 and one would expect to find the XAMPP Welcome page if your port config. edits were accepted.

On the other hand MySQL normally uses host localhost on port 3306 by default and if you run xampp-portcheck.exe in the xampp folder it will reveal the port MySQL is currently using - default is:
MySQL 3306 C:\xampp\mysql\bin\mysqld.exe

To change this port or indeed any MySQL configurations then you would need to edit the my.cnf file in the xampp\mysql\bin folder, but changing the port is not normally required.
(or it might look like a shortcut my file - drag into text editor to read and edit).

There is no MySQL host localhost:8080 configured.
Change this back to the default in test.php if you find MySQL on port 3306:
$con = mysql_connect("localhost","root","");

Delete this entry in PMA if MySQL on port 3306:
root localhost:8080 No ALL PRIVILEGES Yes

Then see how you go with your test.
If your test.php is in the htdocs folder and Apache is on port 8080 and MySQL is on port 3306 and you have cleared your browser's cache, then:
http://localhost:8080/test.php


Also, if you will be connected to the Internet when running your XAMPP server then please read the readme_en.txt file in the xampp folder especially the Security info.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: mysql_connect won't work

Postby nd00jan » 18. January 2009 23:47

Izzy wrote:What address are you typing in the address bar of your browser to load test.php?


It is the Apache web server that uses localhost on port 80 by default or when changed, as in your case, 8080 and one would expect to find the XAMPP Welcome page if your port config. edits were accepted.

On the other hand MySQL normally uses host localhost on port 3306 by default and if you run xampp-portcheck.exe in the xampp folder it will reveal the port MySQL is currently using - default is:
MySQL 3306 C:\xampp\mysql\bin\mysqld.exe

To change this port or indeed any MySQL configurations then you would need to edit the my.cnf file in the xampp\mysql\bin folder, but changing the port is not normally required.
(or it might look like a shortcut my file - drag into text editor to read and edit).

There is no MySQL host localhost:8080 configured.
Change this back to the default in test.php if you find MySQL on port 3306:
$con = mysql_connect("localhost","root","");

Delete this entry in PMA if MySQL on port 3306:
root localhost:8080 No ALL PRIVILEGES Yes

Then see how you go with your test.
If your test.php is in the htdocs folder and Apache is on port 8080 and MySQL is on port 3306 and you have cleared your browser's cache, then:
http://localhost:8080/test.php


Also, if you will be connected to the Internet when running your XAMPP server then please read the readme_en.txt file in the xampp folder especially the Security info.


Thanks for the help! Very much appreciated! This was useful information to me in order to solve my problem, and also to know more about how these things generally work. The only thing I had to do was to set mysql_connect to just "localhost" and I also deleted the entry as you suggested, and then it all worked like it should. I checked which port MySQL was using (with xampp-portcheck.exe) and it used 3306 as you said it normally would do, I also got information about which port apache was using and it says port 80, which is a bit strange consider that I changed the httpd.conf to 8080. But, anyway it's working.
nd00jan
 
Posts: 2
Joined: 18. January 2009 00:02


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 198 guests