Jump to content

PHP cannot conect to MYSQL


vladqui

Recommended Posts

Hello

I have been working with php and mysql for some time, but today I am totally blocked with this new problem.

 

I installed Apache 2.2.11, MySQL 5.0.45  with MySQL Client 5.1.11 and PHP 5.3.3.

All of this on a PC  running Windows Server 2008

 

I also installed a couple of MySQL GUI´s and uploaded the Database.

 

Apache is working  OK, it restarts with no problem

MySQL seems to be working OK and I can edit the tables

PHP appears to be OK and I get the phpInfo screen where strangely there is no Active  Link.

 

When I try to connect to the database, the system stalls until I get the message:

Fatal error: Maximum execution time of 30 seconds exceeded in ...

 

There is no error messge and the server error log is empty, since PHP has never connected to the DB.

 

All the corresponding extentions are habilitated in php.ini and the extentions directory is correct in httpd.conf.

 

At this moment I am out of ideas....  PLEASE help.

 

Regards,

 

Vladimir

Link to comment
https://forums.phpfreaks.com/topic/224771-php-cannot-conect-to-mysql/
Share on other sites

Hi

It is the simplest code, just to test:

 

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

if (!$link) {

    die('Could not connect: ' . mysql_error());

}

echo 'Connected successfully';

mysql_close($link);

 

Nothing happens until the Maximum execution time warning appears.

No other error, Nothing...

 

 

And MySQL is running? On localhost? On port 3306?

 

Open up a command prompt (Start > Run "cmd.exe") and type

telnet localhost 3306

If the screen doesn't clear and you don't see a bunch of weird characters then MySQL is not running where PHP is expecting to find it.

;D  Thanks Pikachu

 

That was the idea I needed...!

I forgot to mention I am working this installation on a Intranet, maybe that is why the server name is not properly translated into its IP.  So PHP did not know where to look for the DB server.

 

I simply replaced every instance of 'localhost' by '127.0.0.1' on each configuration file and.... VOILA  ::) magically everything started to work as expected.

 

This small piece of information saved me many more hours of frustration.

 

Happy New Year...!

 

VQ

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.