# PHP/MySQL/Apache Connection Problems (10061)



## wirvin (Oct 20, 2005)

I am having the following problem with the following configuration:
PHP 5.0.2
MySQL 4.0.20d
Apache 1.3.33
Windows XP Professional

PHP is working, as demonstrated by the phpinfo script I have run in the browser.

(<?php phpinfo() ?> )​MySQL will work fine from the command line, and starts as a service in Windows.

Apache is working, and will load my PHP pages, as well as html pages. However, when I try to use PHP to access MySQL, I get the following error “Cannot connect to the database server on ‘localhost’ (10061)”. I will walk through the steps I had to take to configure the server.

1.	Installed MySQL 4.0.20d to c:\mysql
a.	From the command line: 
c:\mysql\bin\mysql -u root mysql
mysql>UPDATE User Password=PASSWORD(‘new password’) 
>WHERE User=”root”;
mysql>FLUSH PRIVILEGES;​2.	Unzipped PHP 5.0.2 to c:\php
a.	Copied the “php.ini-dist” file to c:\windows.
b.	Renamed to “php.ini” and made following changes.
i.	extension_dir = “c:\php\ext”
ii.	Enabled “php_mysql.dll” extension.
iii.	session.save_path = “c:\windows\temp”​c.	Copied php_mysql.dll, php_mysqli.dll, libmysql.dll, and libmysqli.dll to c:\windows. (This was the only way I could get PHP startup to find the files).​3.	Installed Apache 1.3.33 to c:\Apache.

I did notice one thing. When I run phpinfo, under the mysql section, it lists the client API as 3.23. Does PHP5 not have support for MySQL 4.x? To further clarify, I have tried the same steps with differing combinations of PHP 4.3.9 and IIS, with the same results. The script I am using in PHP is as follows
<?php
$host = ‘localhost’;
$user = ‘root’;
$pass = ‘password’;
$dbcnx = @mysql_connect($host, $user, $pass);
if(!$dbcnx) { exit(‘mysqlerror()’) }
?>​This script works fine on remote servers, but I cannot get it to work on my local machine. Any suggestions? Thanks.


----------



## tgo (Jul 5, 2005)

php5 does work with mysql 4 because thats what I use.

Its probally something easy you are missing so I would go in telnet (start - run - cmd) and do

telnet localhost 3306

if your on a network try:

telnet internal_ip 3306

then your external ip (can be found at www.whatismyip.com )

telnet external_ip 3306

if you cant connect to any of these then your mysql server isnt running right. Is the mysqldnt.exe (something close to that) running in the process list?

if you can connect to one of these and your php script cant that means your php.ini isnt correct. Heres what i have in my php.ini involving mysql.
-----------------------
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; Windows: "\path1;\path2"
include_path = "c:\php\ext;c:\mysql\bin"

extension=php_mysql.dll

-----------------------

make sure you have that extension line uncommented (wihtout a ; in front the line) and make sure you have the path to mysql so it knows where to look for the database.


----------



## wirvin (Oct 20, 2005)

The key seems to be adding port 3306, so I will try that. The thing that gets me is that I am running PHP4.3/MySQL 4.0/Apache 1.3.33 on another (Windows 98SE) computer, and it is working wonderfully. The only difference is that MySQL is running as a service (mysqld-nt.exe) on the XP machine, and on the Windows 98SE machine I had to copy the shortcut (mysqld.exe) to my startup folder for it to start up automatically (It also worked to start MySQL manually after startup). I haven't added the "c:\mysql\bin" to my include_path, but I didn't do that on my 98SE machine, either. 

The MySQL server seems to be running fine. It does start automatically as a service in Windows XP, and I can access it from the command prompt with no problems. As I said, my PHP scripts work fine on the Apache server. The only thing I can’t do is access MySQL with PHP. Could you email me a copy of your php.ini file ([email protected]) so I can see what I may have missed? I would sure appreciate it. Thanks.

I do have a question about your include_path line. Did you have to move your php_mysql.dll file to the c:\windows\system32 directory for PHP startup to see it, or did adding c:\php\ext to your include_path allow startup to find that file? I had to move that file and libmysql.dll to system32 in order for PHP to startup properly.


----------



## shylock (Dec 14, 2004)

*sameProb*

I'm having the same problem on my local box and I tried everything (or so it seems) including the telnet stuff mentioned above. When I want to go to any page that does not include interaction with the database things are fine. When I try to log in or see a product, the page refreshes and remains. The product images/paths show up fine since the images from the database are being produced. This could be just a Windows thing because I don't have this sort of problem with Fedora Core/Linux.


----------

