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
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...

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

;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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.