954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

unable to connect PHP with Mysql

I am new to PHP. I am trying to connect mysql with PHP with
mysql_connect but i m getting
"A link to the server could not be established"
I have used ODBC 3.51 driver for odbc and made connections with odbc with odbc_connect
but i don't know how to connect it with mysql_connect and fire mysql_-----queries.
Is there any specific driver for tht?

bhavna_816
Junior Poster
116 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Why are you using ODBC connction r u using windows machine or linux server ? Arey you use MYSQL database or other?

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 
Why are you using ODBC connction r u using windows machine or linux server ? Arey you use MYSQL database or other?



I told tht i have used ODBC 3.51 driver and used odbc_connect and so on......... queries ....
but now i have to use mysql_connect and so on........ queries .
I have Windows Server 2003 Service Pack 1 version of windows.

bhavna_816
Junior Poster
116 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Are you sure the server is running? (check the obvious first :-)

Also check the order of the arguments to mysql_connect - it's server, user, password. (I somehow manage to forget that every single time I use mysql, and PHP yells at me for it a lot :-)

If the mysql and web servers are on different computers, make sure there isn't a firewall blocking them (sounds like something Windows Firewall would do...)

mmiikkee12
Posting Whiz in Training
274 posts since Oct 2004
Reputation Points: 17
Solved Threads: 5
 

You do know you need to copy the mysql dlls from the mysql directory to the PHP one and point the PHP config file at them?

This is probably as in PHP5 they removed MySQL support (was in by deafult before)

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,820
Solved Threads: 600
 

Once you have completed all the above you should use the following code to connect -

mysql_connect('HOSTNAME', 'USERNAME', 'PASSWORD');

if(mysql_error()) {
echo mysql_errno().'

mysql_error();
}

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 

Might be worthwhile doing an advanced search for all forum posts where i have posted as I member a while ago i posted a zip file constaining a whole load of PHP/MySQL example code like that.

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,820
Solved Threads: 600
 
You do know you need to copy the mysql dlls from the mysql directory to the PHP one and point the PHP config file at them? This is probably as in PHP5 they removed MySQL support (was in by deafult before)

you dont need to copy mysql dlls even in php 5 u just hav to add php folder and mysql folder to the windows path

w_3rabi
Junior Poster
160 posts since Dec 2006
Reputation Points: 18
Solved Threads: 9
 
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,820
Solved Threads: 600
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You