Connecting PHP to MySQL on Windows

Connecting PHP to MySQL on Windows

am 06.01.2011 07:13:50 von michael manning

--0016364edb0cc992e80499276765
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I have installed MySQL 5.1.52, Apache 2.2.15 and PHP 5.3.2 on my Windows
Vista computer.
The MySQL works fine with the command line client and I have tested the
Apache and PHP and it appears fine when I test this with the phpinfo()
function. There is just one exception - I cannot connect to a MySQL
database from within a PHP script. I have installed the MySQLi extension

With a simple script such as:
$link = mysqli_connect('localhost', 'user', 'my_password', 'my_db');

if (!$link) {
die('Connect Error: ' . mysqli_connect_error());
}
?>

I receive the following error message in the php error log:
[06-Jan-2011 16:38:35] PHP Warning: mysqli_connect(): [2002] A connection
attempt failed because the connected party did not (trying to connect via
tcp://localhost:3306) in C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\php\connect_error.php on line 19

[06-Jan-2011 16:38:35] PHP Warning: mysqli_connect(): (HY000/2002): A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.

in C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\php\connect_error.php on line 19

[06-Jan-2011 16:38:35] PHP Fatal error: Maximum execution time of 30
seconds exceeded in C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\php\connect_error.php on line 19

My php.ini file has the following lines re extensions :

[PHP_LDAP]
extension=php_ldap.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OPENSSL]
extension=php_openssl.dll
and there are no error message that it cannot find the extension. These are
in the windows path and in the extension directory specified in php.ini

I have checked the firewall but it seems to be ok and the mysql server and
apache server on the same machine.
I have installed this correctly in the past but am having no luck with this
installation.

Any hints of where to look and what to try would be most welcome.

regards

Mike
michaelgmanning@gmail.com

--0016364edb0cc992e80499276765--

Re: Connecting PHP to MySQL on Windows

am 06.01.2011 17:49:36 von Daniel Brown

On Thu, Jan 6, 2011 at 01:13, michael manning w=
rote:
> Hi,
>
> I have installed MySQL 5.1.52, Apache 2.2.15 and PHP 5.3.2 on my Windows
> Vista computer.
> The MySQL works fine with the command line client and I have tested the
> Apache and PHP and it appears fine when I test this with the phpinfo()
> function. =A0There is just one exception - I cannot connect to a MySQL
> database from within a PHP script. =A0I have installed the MySQLi extensi=
on

I know you said MySQL works fine from the CLI, but a stupid
question: is the MySQL server running while you're trying to test from
PHP? And, if so, on what port does netstat show it running?

--=20

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Connecting PHP to MySQL on Windows

am 07.01.2011 03:12:59 von michael manning

--0003255749263db3030499382835
Content-Type: text/plain; charset=ISO-8859-1

Hi Daniel,

When testing with the CLI, netstat shows:
=========
C:\Users\mmanning>netstat -b

Active Connections

Proto Local Address Foreign Address State
TCP 127.0.0.1:80 mmanning-PC:49391 ESTABLISHED
[httpd.exe]
TCP 127.0.0.1:3306 mmanning-PC:49338 ESTABLISHED
[mysqld.exe]
TCP 127.0.0.1:27015 mmanning-PC:49157 ESTABLISHED
[AppleMobileDeviceService.exe]
TCP 127.0.0.1:49157 mmanning-PC:27015 ESTABLISHED
[iTunesHelper.exe]
TCP 127.0.0.1:49262 mmanning-PC:49263 ESTABLISHED
[firefox.exe]
TCP 127.0.0.1:49263 mmanning-PC:49262 ESTABLISHED
[firefox.exe]
TCP 127.0.0.1:49264 mmanning-PC:49265 ESTABLISHED
[firefox.exe]
TCP 127.0.0.1:49265 mmanning-PC:49264 ESTABLISHED
[firefox.exe]
TCP 127.0.0.1:49338 mmanning-PC:3306 ESTABLISHED
[mysql.exe]
TCP 127.0.0.1:49391 mmanning-PC:http ESTABLISHED
[firefox.exe]
TCP 130.130.48.79:49208 nimmo-37:8080 ESTABLISHED
[googletalk.exe]
TCP 130.130.48.79:49238 nimue-37:8080 ESTABLISHED
[chrome.exe]
TCP 130.130.48.79:49344 nimue-37:8080 ESTABLISHED
[chrome.exe]
=======

I ran the same test script on my computer at home without difficulty. It is
running Apache 2.2.16, PHP 5.3.3 and MySQL 5.1.51 on Windows XP Professional
SP3.

regards

Mike
michaelgmanning@gmail.com

On Fri, Jan 7, 2011 at 3:49 AM, Daniel Brown wrote:

> On Thu, Jan 6, 2011 at 01:13, michael manning
> wrote:
> > Hi,
> >
> > I have installed MySQL 5.1.52, Apache 2.2.15 and PHP 5.3.2 on my Windows
> > Vista computer.
> > The MySQL works fine with the command line client and I have tested the
> > Apache and PHP and it appears fine when I test this with the phpinfo()
> > function. There is just one exception - I cannot connect to a MySQL
> > database from within a PHP script. I have installed the MySQLi extension
>
> I know you said MySQL works fine from the CLI, but a stupid
> question: is the MySQL server running while you're trying to test from
> PHP? And, if so, on what port does netstat show it running?
>
> --
>
> Network Infrastructure Manager
> Documentation, Webmaster Teams
> http://www.php.net/
>

--0003255749263db3030499382835--

Re: Connecting PHP to MySQL on Windows

am 07.01.2011 03:25:12 von Daniel Brown

On Thu, Jan 6, 2011 at 21:12, michael manning wrote:
> Hi Daniel,
> When testing with the CLI, netstat shows:
[snip!]

What happens when you swap out 'localhost' for '127.0.0.1' in the
connection routine? If that works, check to make sure your hosts file
properly designates 127.0.0.1 as 'localhost' (by editing
c:\windows\system32\drivers\etc\hosts I believe.... been a while since
I've done it on Windows).

--

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Connecting PHP to MySQL on Windows

am 07.01.2011 05:18:45 von michael manning

--0022152d7e0b08303f049939ea23
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I swapped out 'localhost" for '127.0.0.1' in the url but this had no effect.

I had a look at my hosts file at c:\windows\system32\drivers\etc and this
contained:

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
::1 localhost

and so this seems fine as well.

cheers

Mike

On Fri, Jan 7, 2011 at 1:25 PM, Daniel Brown wrote:

> On Thu, Jan 6, 2011 at 21:12, michael manning
> wrote:
> > Hi Daniel,
> > When testing with the CLI, netstat shows:
> [snip!]
>
> What happens when you swap out 'localhost' for '127.0.0.1' in the
> connection routine? If that works, check to make sure your hosts file
> properly designates 127.0.0.1 as 'localhost' (by editing
> c:\windows\system32\drivers\etc\hosts I believe.... been a while since
> I've done it on Windows).
>
> --
>
> Network Infrastructure Manager
> Documentation, Webmaster Teams
> http://www.php.net/
>

--0022152d7e0b08303f049939ea23--

Re: Connecting PHP to MySQL on Windows

am 07.01.2011 21:06:35 von Gavin Chalkley

--001636283612c608ef0499472760
Content-Type: text/plain; charset=ISO-8859-1

Mike,

A plain HOST file should have the commented part at the top, and only 1
reference to localhost unless you are creating Virtual hosts.

I would suggest removing the "::1" line

BR

Gavin

On Fri, Jan 7, 2011 at 4:18 AM, michael manning
wrote:

> Hi,
>
> I swapped out 'localhost" for '127.0.0.1' in the url but this had no
> effect.
>
> I had a look at my hosts file at c:\windows\system32\drivers\etc and this
> contained:
>
> # Copyright (c) 1993-2006 Microsoft Corp.
> #
> # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
> #
> # This file contains the mappings of IP addresses to host names. Each
> # entry should be kept on an individual line. The IP address should
> # be placed in the first column followed by the corresponding host name.
> # The IP address and the host name should be separated by at least one
> # space.
> #
> # Additionally, comments (such as these) may be inserted on individual
> # lines or following the machine name denoted by a '#' symbol.
> #
> # For example:
> #
> # 102.54.94.97 rhino.acme.com # source server
> # 38.25.63.10 x.acme.com # x client host
>
> 127.0.0.1 localhost
> ::1 localhost
>
> and so this seems fine as well.
>
> cheers
>
> Mike
>
> On Fri, Jan 7, 2011 at 1:25 PM, Daniel Brown wrote:
>
> > On Thu, Jan 6, 2011 at 21:12, michael manning > >
> > wrote:
> > > Hi Daniel,
> > > When testing with the CLI, netstat shows:
> > [snip!]
> >
> > What happens when you swap out 'localhost' for '127.0.0.1' in the
> > connection routine? If that works, check to make sure your hosts file
> > properly designates 127.0.0.1 as 'localhost' (by editing
> > c:\windows\system32\drivers\etc\hosts I believe.... been a while since
> > I've done it on Windows).
> >
> > --
> >
> > Network Infrastructure Manager
> > Documentation, Webmaster Teams
> > http://www.php.net/
> >
>



--
Best regards,

Gavin C

--001636283612c608ef0499472760--

Re: Connecting PHP to MySQL on Windows

am 07.01.2011 22:18:15 von Daniel Brown

On Fri, Jan 7, 2011 at 15:06, Gavin Chalkley wrote:
> Mike,
>
> A plain HOST file should have the commented part at the top, and only 1
> reference to localhost unless you are creating Virtual hosts.
>
> I would suggest removing the "::1" line

As long as he never plans to use IPv6 on there, that would be fine.

--

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php