Link to home
Create AccountLog in
Avatar of Billy Ma
Billy MaFlag for Hong Kong

asked on

Cannot Connect

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10048) in C:\Web Server\foa_appsys\portass\port_assignment\getdata.php on line 589
Could not connect

Why I always get this warning on my PHP page? How to fix it?
Avatar of CWS (haripriya)
CWS (haripriya)
Flag of India image

how you are connecting to the database? can you post your code?
Avatar of Billy Ma


$link = mysql_connect($DB_SERVER, $DB_LOGIN, $DB_PASSWD) or die("Could not connect");
            mysql_select_db($DB_PORTASS_NAME, $link) or die("Could not select database");

            mysql_query("LOCK TABLES reboot_control READ");      

            $query = "SELECT code FROM reboot_control WHERE `staffno` = '$staffno'";
            $str = mysql_query($query, $link) or die("Query failed");
            mysql_query("UNLOCK TABLES");
Is MySQl installed properly in your computer?
Avatar of Ryan Chong
Make sure your MySQL Service is running?
My MYSQL Server is version 4.1
in what port it is installed?
Also recheck login and pass.
Oh... sorry... I need a coffee... it's not a login/pass issue.
try using the port number

$link = mysql_connect("localhost:3306", $DB_LOGIN, $DB_PASSWD) or die("Could not connect");
But this is no problems on the live server......this problems only on my local machine...i don't know why...
You seem to be running Windows.

maybe you have something like this in your mysql forlder:

......../mysql/MySQL Administrator/MySQLSystemTrayMonitor.exe

or something similar.

This could help you see if server is up and running, etc.
i think firewall in blocking.
Good idea cyberwebservice...

try to telnet from MSDOS:

telnet localhost 3306

and see if you either get an error or you can connect.
no....the problems sometime ok, sometime not ok...
If the query need to return large amount of result, the query failed. If not, the query is ok..i don't know why.
try not to luck the table and re unlock it, leave it for MySQL to lock and unlock the table automatically.
whats the value of $DB_SERVER?
>>If the query need to return large amount of result, the query failed. If not, the query is ok..i don't know why.

Perhaps it's your page or database connection timeout, how large is the amount of result you pulled out? Perhaps you can increase the performance by restructure the query or database design.
I've seen a few posts with similar problems.

If this is related, it has to do with your anti-virus software. I've seen this with McAfee, and the fix is to add the write directory to the ignore list. What happens is the application server makes a call to the MySQL server which trys to process the data but based on the virus scan doesn't return a result in time, throwing a can not connect' error.

I hope this helps!
To Clarify:

The write directory (or Temp directory) of MySQL, not your website. You can find this in the MySQL Administrator under "Startup Variables" > "General Parameters" > Directories.
THanks for your reply. Should I increase the time limit?? But my MySQL has no time limit and no max connection limit..

what values should I type in the write directory as you mentioned above?
Avatar of PhiveWeeze
Flag of Canada image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account