Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to connect to MySQL

Status
Not open for further replies.

jgroom

Programmer
Feb 23, 2005
8
GB
I am using the following statement to connect to MySQL using PHP on Windows 2000.
$connect = mysql_connect("localhost", "root", "azbycx") or die (mysql_error());

Unfortunately I get the following error.
Warning: mysql_connect() [function.mysql-connect.chm]: Can't connect to MySQL server on 'localhost' (10061) in D:\xyz\phptest.php on line 3
Can't connect to MySQL server on 'localhost' (10061)

I can connect to and manipulate MySQL via the command prompt without problem.

Does anybody have any idea what I should be looking at ?

All help VERY welcome.
 
is your mysql server runing ?
do you have an entry in your hosts called localhost that points to 127.0.0.1 ?
 
Thanx Ingresman.

Yes to both questions.

Its just the web page which won't connect.
 
how strange,

can you post the code please?
Can you connect to the server from any other platform/language or even any other .php page.

 
The connect code is given in my original post.

I can connect via command line and also via SQLyog.
 
yes i appreciate that but could you post a snippet which demonstrates the entire fail? including any includes etc. I'm thinking something may be causing you a problem ibn the rest of the code and I can cut it and try it for myself.
The connect looks ok, can you give the versions of mysql and php as well just in case there is a comptability issue.
cheers
 
OK - I understand.

The entire page code is as follows :-
<?php
// phpinfo();
$connect = mysql_connect("localhost", "root", "azbycx") or die (mysql_error());
$create = mysql_query("CREATE DATABASE IF NOT EXISTS movies") or die ("Cannot create DB movies");
mysql_select_db("movies");
$sql = "CREATE TABLE movie (id int() NOT NULL auto_increment,name varchar(50) NOT NULL)";
$result = mysql_query($sql) or die ("Cannot create TABLE movie");
echo "DB and 1 table created";
?>


This essentially my first attempt at PHP/MySQL and is copied (almost) from a book 'PHP5,Apache,MySQL web development'.

PHP version is 4
MySQL version is 4.1

Maybe it's because I am using v4 of PHP.

Regards
 
I've tried your code and it's ok on my machine.
Now my mysql server is 3.23.52 I'm wondering if it's a problem with the client libraries in 4.1, I recall a change has been made.
At the command line can you type c:\php\php -v (assuming your php is at c:\php\php and post the exact version number please.
Also can you uncomment the phpinfo and post the results and let's see what versions your generally running
I'm thinking that it is something in the PHP as you can get to the server from other places.
Have you changed the port number for the mysql service by any chance ?
 
OK - here goes :-


PHP Version 4.3.1

System Windows NT localhost 5.0 build 2195
Build Date Feb 15 2003 23:02:25
Server API ISAPI
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINNT\php.ini
PHP API 20020918
PHP Extension 20020429
Zend Extension 20021010
Debug Build no
Thread Safety enabled
Registered PHP Streams php, http, ftp, compress.zlib

Zend logo This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies

PHP Credits
Configuration
PHP Core
Directive Local Value Master Value
allow_call_time_pass_reference On On
allow_url_fopen On On
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_functions no value no value
display_errors On On
display_startup_errors On On
doc_root .\ .\
docref_ext .chm .chm
docref_root d:\php\manual\ d:\php\manual\
enable_dl On On
error_append_string no value no value
error_log no value no value
error_prepend_string no value no value
error_reporting 2047 2047
expose_php On On
extension_dir ./ ./
file_uploads On On
gpc_order GPC GPC
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .\ .\
log_errors On On
log_errors_max_len 1024 1024
magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
max_execution_time 30 30
max_input_time 60 60
open_basedir no value no value
output_buffering no value no value
output_handler no value no value
post_max_size 8M 8M
precision 12 12
register_argc_argv On On
register_globals On On
report_memleaks On On
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from me@localhost.com me@localhost.com
sendmail_path no value no value
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir no value no value
user_dir no value no value
variables_order EGPCS EGPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On

ISAPI
Server Variable Value
CONTENT_LENGTH 0
PATH_TRANSLATED D:\joeBrown\phptest.php
REMOTE_ADDR 127.0.0.1
REMOTE_HOST 127.0.0.1
REQUEST_METHOD GET
SERVER_NAME localhost
SERVER_PORT 80
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE Microsoft-IIS/5.0
APPL_MD_PATH /LM/W3SVC/1/ROOT/joebrowns
APPL_PHYSICAL_PATH D:\joeBrown\
INSTANCE_ID 1
INSTANCE_META_PATH /LM/W3SVC/1
URL /joebrowns/phptest.php
ALL_HTTP HTTP_ACCEPT:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 HTTP_CONNECTION:keep-alive HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 HTTP_COOKIE:elucid=last%5Fbought=23%2F02%2F2005&customer=0000020097; ASPSESSIONIDQCRDDSSS=DIPBFEDCMKMMGLGDPOKBOGCP HTTP_ACCEPT_ENCODING:gzip,deflate HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_KEEP_ALIVE:300
HTTPS off
SCRIPT_NAME /joebrowns/phptest.php
SERVER_PORT_SECURE 0

bcmath
BCMath support enabled

calendar
Calendar support enabled

com
Directive Local Value Master Value
com.allow_dcom Off Off
com.autoregister_casesensitive On On
com.autoregister_typelib Off Off
com.autoregister_verbose Off Off
com.typelib_file no value no value

ctype
ctype functions enabled

ftp
FTP support enabled

mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.49

Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout -1 -1
mysql.default_host localhost localhost
mysql.default_password no value no value
mysql.default_port 3306 3306
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode On On

odbc
ODBC Support enabled
Active Persistent Links 0
Active Links 0
ODBC library Win32

Directive Local Value Master Value
odbc.allow_persistent On On
odbc.check_persistent On On
odbc.default_db no value no value
odbc.default_pw no value no value
odbc.default_user no value no value
odbc.defaultbinmode return as is return as is
odbc.defaultlrl return up to 4096 bytes return up to 4096 bytes
odbc.max_links Unlimited Unlimited
odbc.max_persistent Unlimited Unlimited

overload
User-Space Object Overloading Support enabled

pcre
PCRE (Perl Compatible Regular Expressions) Support enabled
PCRE Library Version 3.92 11-Sep-2002

session
Session Support enabled
Registered save handlers files user

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain softwaremine.co.uk softwaremine.co.uk
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_dividend 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path c:\winnt\temp c:\winnt\temp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off

standard
Regex Library Bundled library enabled
Dynamic Library Support enabled
Internal Sendmail Support for Windows enabled

Directive Local Value Master Value
assert.active 1 1
assert.bail 0 0
assert.callback no value no value
assert.quiet_eval 0 0
assert.warning 1 1
auto_detect_line_endings 0 0
default_socket_timeout 60 60
safe_mode_allowed_env_vars PHP_ PHP_
safe_mode_protected_env_vars LD_LIBRARY_PATH LD_LIBRARY_PATH
url_rewriter.tags a=href,area=href,frame=src,input=src,form=,fieldset= a=href,area=href,frame=src,input=src,form=,fieldset=
user_agent no value no value

tokenizer
Tokenizer Support enabled

wddx
WDDX Support enabled

xml
XML Support active
XML Namespace Support active
EXPAT Version 1.95.2

zlib
ZLib Support enabled
Compiled Version 1.1.4
Linked Version 1.1.4

Directive Local Value Master Value
zlib.output_compression Off Off
zlib.output_compression_level -1 -1
zlib.output_handler no value no value

Additional Modules
Module Name

Environment
Variable Value
ALLUSERSPROFILE C:\Documents and Settings\All Users.WINNT
CATALINA_HOME C:\jakarta-tomcat
CLASSPATH .;C:\jakarta-tomcat\common\lib\servlet.jar;C:\jakarta-tomcat\server\lib
CommonProgramFiles C:\Program Files\Common Files
COMPUTERNAME JGROOM-HOME
ComSpec C:\WINNT\system32\cmd.exe
INCLUDE C:\Program Files\Microsoft.NET\FrameworkSDK\include\;C:\Program Files\Microsoft Visual Studio .NET\Vc7\include\
JAVA_HOME C:\Program Files\Java
LIB C:\Program Files\Microsoft.NET\FrameworkSDK\Lib\;C:\Program Files\Microsoft Visual Studio .NET\Vc7\lib\
LM_LICENSE_FILE C:\Compuware\UNIFACE JTi Server\Programs
NetSamplePath C:\PROGRA~1\MICROS~1.NET\FRAMEW~1\Samples
NUMBER_OF_PROCESSORS 1
OS Windows_NT
Os2LibPath C:\WINNT\system32\os2\dll;
Path C:\Program Files\Microsoft.NET\FrameworkSDK\Bin\;C:\Program Files\Microsoft Visual Studio .NET\Common7\IDE\;C:\WINNT\Microsoft.NET\Framework\v1.0.3705\;C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\PROGRA~1\ULTRAE~1;C:\Compuware\UNIFACE JTi Server\Programs;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\MSSQL7\BINN;C:\Program Files\Symantec\pcAnywhere\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;"C:\Program Files\Symantec\Norton Ghost 2003\";"C:\Program Files\Java\bin";C:\Program Files\MySQL\MySQL Server 4.1\bin
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE x86
PROCESSOR_IDENTIFIER x86 Family 6 Model 4 Stepping 2, AuthenticAMD
PROCESSOR_LEVEL 6
PROCESSOR_REVISION 0402
ProgramFiles C:\Program Files
SystemDrive C:
SystemRoot C:\WINNT
TEMP C:\WINNT\TEMP
TMP C:\WINNT\TEMP
USERPROFILE C:\Documents and Settings\Default User.WINNT
VSCOMNTOOLS "C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\"
windir C:\WINNT

PHP Variables
Variable Value
PHP_SELF /joebrowns/phptest.php
_COOKIE["elucid"] last_bought=23/02/2005&customer=0000020097
_COOKIE["ASPSESSIONIDQCRDDSSS"] DIPBFEDCMKMMGLGDPOKBOGCP
_SERVER["ALL_HTTP"] HTTP_ACCEPT:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 HTTP_CONNECTION:keep-alive HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 HTTP_COOKIE:elucid=last%5Fbought=23%2F02%2F2005&customer=0000020097; ASPSESSIONIDQCRDDSSS=DIPBFEDCMKMMGLGDPOKBOGCP HTTP_ACCEPT_ENCODING:gzip,deflate HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_KEEP_ALIVE:300
_SERVER["HTTPS"] off
_SERVER["SCRIPT_NAME"] /joebrowns/phptest.php
_SERVER["HTTP_COOKIE"] elucid=last%5Fbought=23%2F02%2F2005&customer=0000020097; ASPSESSIONIDQCRDDSSS=DIPBFEDCMKMMGLGDPOKBOGCP
_SERVER["CONTENT_LENGTH"] 0
_SERVER["PATH_TRANSLATED"] D:\\joeBrown\\phptest.php
_SERVER["REMOTE_ADDR"] 127.0.0.1
_SERVER["REMOTE_HOST"] 127.0.0.1
_SERVER["REQUEST_METHOD"] GET
_SERVER["SERVER_NAME"] localhost
_SERVER["SERVER_PORT"] 80
_SERVER["SERVER_PROTOCOL"] HTTP/1.1
_SERVER["SERVER_SOFTWARE"] Microsoft-IIS/5.0
_SERVER["APPL_MD_PATH"] /LM/W3SVC/1/ROOT/joebrowns
_SERVER["APPL_PHYSICAL_PATH"] D:\\joeBrown\\
_SERVER["INSTANCE_ID"] 1
_SERVER["INSTANCE_META_PATH"] /LM/W3SVC/1
_SERVER["URL"] /joebrowns/phptest.php
_SERVER["PHP_SELF"] /joebrowns/phptest.php
_SERVER["HTTP_ACCEPT"] text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
_SERVER["HTTP_ACCEPT_LANGUAGE"] en-us,en;q=0.5
_SERVER["HTTP_CONNECTION"] keep-alive
_SERVER["HTTP_HOST"] localhost
_SERVER["HTTP_USER_AGENT"] Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
_SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate
_SERVER["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.7
_SERVER["HTTP_KEEP_ALIVE"] 300
_SERVER["DOCUMENT_ROOT"] c:\\inetpub\\_SERVER["argv"]

Array
(
)

_SERVER["argc"] 0
_ENV["ALLUSERSPROFILE"] C:\\Documents and Settings\\All Users.WINNT
_ENV["CATALINA_HOME"] C:\\jakarta-tomcat
_ENV["CLASSPATH"] .;C:\\jakarta-tomcat\\common\\lib\\servlet.jar;C:\\jakarta-tomcat\\server\\lib
_ENV["CommonProgramFiles"] C:\\Program Files\\Common Files
_ENV["COMPUTERNAME"] JGROOM-HOME
_ENV["ComSpec"] C:\\WINNT\\system32\\cmd.exe
_ENV["INCLUDE"] C:\\Program Files\\Microsoft.NET\\FrameworkSDK\\include\\;C:\\Program Files\\Microsoft Visual Studio .NET\\Vc7\\include\\
_ENV["JAVA_HOME"] C:\\Program Files\\Java
_ENV["LIB"] C:\\Program Files\\Microsoft.NET\\FrameworkSDK\\Lib\\;C:\\Program Files\\Microsoft Visual Studio .NET\\Vc7\\lib\\
_ENV["LM_LICENSE_FILE"] C:\\Compuware\\UNIFACE JTi Server\\Programs
_ENV["NetSamplePath"] C:\\PROGRA~1\\MICROS~1.NET\\FRAMEW~1\\Samples
_ENV["NUMBER_OF_PROCESSORS"] 1
_ENV["OS"] Windows_NT
_ENV["Os2LibPath"] C:\\WINNT\\system32\\os2\\dll;
_ENV["Path"] C:\\Program Files\\Microsoft.NET\\FrameworkSDK\\Bin\\;C:\\Program Files\\Microsoft Visual Studio .NET\\Common7\\IDE\\;C:\\WINNT\\Microsoft.NET\\Framework\\v1.0.3705\\;C:\\Program Files\\Microsoft Visual Studio .NET\\Vc7\\bin\\;C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;C:\\PROGRA~1\\ULTRAE~1;C:\\Compuware\\UNIFACE JTi Server\\Programs;C:\\Program Files\\Microsoft SQL Server\\80\\Tools\\BINN;C:\\MSSQL7\\BINN;C:\\Program Files\\Symantec\\pcAnywhere\\;C:\\Program Files\\Microsoft SQL Server\\80\\Tools\\Binn\\;\"C:\\Program Files\\Symantec\\Norton Ghost 2003\\\";\"C:\\Program Files\\Java\\bin\";C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin
_ENV["PATHEXT"] .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
_ENV["PROCESSOR_ARCHITECTURE"] x86
_ENV["PROCESSOR_IDENTIFIER"] x86 Family 6 Model 4 Stepping 2, AuthenticAMD
_ENV["PROCESSOR_LEVEL"] 6
_ENV["PROCESSOR_REVISION"] 0402
_ENV["ProgramFiles"] C:\\Program Files
_ENV["SystemDrive"] C:
_ENV["SystemRoot"] C:\\WINNT
_ENV["TEMP"] C:\\WINNT\\TEMP
_ENV["TMP"] C:\\WINNT\\TEMP
_ENV["USERPROFILE"] C:\\Documents and Settings\\Default User.WINNT
_ENV["VSCOMNTOOLS"] \"C:\\Program Files\\Microsoft Visual Studio .NET\\Common7\\Tools\\\"
_ENV["windir"] C:\\WINNT




I am using port 3306 for MySQL
 
That all looks ok and its ok and port 3306 is the oe to use.
Can you do one more thing for me please.
From the command line start a telnet session and connect to the localhost and port 3306, it should come back with the verison of the server your connected to. If it does nothing type asingle return and it shoud do something. You can just close the window after this.
I'm trying t establish if you can actualy talk to the server over tcp/ip. Can you try it from the user that IIS runs in as well please.
 
telnet localhost 3306
or
telnet 127.0.0.1 3306

(returns)

7
4.1.10-nt?&fRFHt28,?dp'nsy&N6`eX

Connection to host lost.

C:\>


I don't know how to do from the IIS user.

Regards
 
ok,
So weve established that your user will connect to the server ok. Getting into the IIS user will entail you logging in to the machine usually into IUSR_comptername, but lets leave that for now.
The way I tested your script was to put it into a text file and run it from the command line.
Can you try getting your php file running it like this:
c:\php\php yourfile.php
If this fails I'm convinced it's a PHP compatability problem,
if it does work it is perhaps a permissions problem in the IIs user.
additional question: have you upgraded mysql on this box ? and do you another box with mysql on that you could remotely conect to ?
 
I get no response.

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>c:\php\php d:\joebrowns\phptest.php

C:\>

I previously had MySQL v3.? which I uninstalled before installing v4. Unfortunately no other MySQL on another box.

Regards
 
interesting it looks like it has worked but hasn't given the echo line.
It's looking good though !.
Can you create a table in the mvovies databases, put a few rows in it using whatever tool, then write a script which selects them and displays them, at least we can repeat the test.
I wonder if your error reporting is set to low in php.ini. Have a look in it and set the errors to all (the file tells you how) and we we get more messages out of it.
 
Hi ingresman

Sorry I didn't get back to you. I decided to uninstall IIS and reinstall it because the problem seemed to be there - command line PHP worked fine.

Unfortunately my machine hangs up just before the end of the install everytime I try it - my PC is getting a bit old - so I think a new one is the answer - then I will reformat this one and use it as a Linux server.

Thanx for all your help tho.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top