Can't login to mysql trough php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JeePee
Forum Newbie
Posts: 9
Joined: Wed Nov 16, 2005 6:00 am

Can't login to mysql trough php

Post by JeePee »

Hi, i have just started out learning php and mysql and i am following a video training session from 3dbuzz.com about connecting to the database trough a php script.

i have used the require command to call a sript where all the login information is stored and the the mysql_connect command mysql_connect ($db_host, $db_user, $db_password) or die "error connecting" to connect to the database. When i run all this it gives me the message error connecting, it does not give me any mysql or php errors so it's hard to figure out what's wrong.

Why do i not get any error messages? and what could be wrong? I am out of ideas.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

put this in your die() you should:

Code: Select all

mysql_connect("host","user","password")
  or die(mysql_error());
provide you with a more detailed description of your problem it will.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

mysql_connect ($db_host, $db_user, $db_password) or die(mysql_error());
then tell us what the error is. php wont auto give you a mysql error without you telling it to give it to you

edit: sigh, im always too slow
JeePee
Forum Newbie
Posts: 9
Joined: Wed Nov 16, 2005 6:00 am

Post by JeePee »

k, done that. it sais my mysql client does not support some authentication mysql 5 needs and that i should concider upgrader my mysql client (using php4 now). I'll download php5 in a minute and then head home and try it out.
I'm just posting this here in case it isn't the solution because i don't have internet at home so i can't say if it's ok rightnow.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

JeePee wrote:k, done that. it sais my mysql client does not support some authentication mysql 5 needs and that i should concider upgrader my mysql client (using php4 now). I'll download php5 in a minute and then head home and try it out.
I'm just posting this here in case it isn't the solution because i don't have internet at home so i can't say if it's ok rightnow.
That's not a PHP problem.

What that is telling you is that the Mysql Client on your server cannot connect to the Mysql Server on the database server. This usually happens when the server and client software for Mysql are different.

Code: Select all

<?php
		 echo mysql_get_client_info();
?>
Create a little test program from the above to get the Mysql client version and then compare that to the version of the Mysql Server you are trying to connect. If they are different then there is your problem. You will need to upgrade the Mysql Client on the server PHP is running.
JeePee
Forum Newbie
Posts: 9
Joined: Wed Nov 16, 2005 6:00 am

Post by JeePee »

“What that is telling you is that the Mysql Client on your server cannot connect to the Mysql Server on the database server. This usually happens when the server and client software for Mysql are different.”

What is the Mysql Client?, I thought it ment php. And what do you mean with “the Mysql Server on the database server”? Aren’t they both the same thing?

I am running the latest version of Apache, php and mysql now (was using php4 when I got the error). I don’t get the error anymore but it still doesn’t work.
I’ll fiddle with the test thing you gave me but I don’t quite get the picture of what you’re saying..

I am connecting locally by the way.
Frosty
Forum Newbie
Posts: 1
Joined: Fri Nov 18, 2005 9:00 am
Location: California
Contact:

Post by Frosty »

I think he meant the server...
Anyways, it seems you have a weird issue. I can only suggest making sure that all of the server somponents are running. Also, make sure you have the right username and password. I am sorry if I come off making you sound dumb, I don't think you are, but that is all I can think of at the moment.

Also, http://us3.php.net/manual/en/ref.mysql.php, I would suggest reading that just to make sure you have the right code.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Mysql has two different parts.

There is the Mysql Server which is what manages the Mysql Database. It is what really executes all of your SQL queries, monitors and manages the health of the database.

Then there is the Mysql Client which is how programs like PHP communicate with the Mysql Server. The Mysql Client is NOT a part of PHP. When you compile PHP with Mysql support you add the ability for PHP to communicate with the Mysql Client on your server and through the client communicate with the Mysql Server.

It is possible for the Mysql Client to be an old version while the Mysql Server is a newer version especially if you upgraded from a Mysql 3.xx version that came default with your linux install. This is why I posted that little snippet of code for checking your linux servers Mysql Client version.

If the Mysql Server is version 5 and Mysql Client is version 4 or 3 then you will not be able to connect to the Mysql Server. Make a small script and run that code I posted and find out the Mysql Client Version. I bet it is not the same as the server.
JeePee
Forum Newbie
Posts: 9
Joined: Wed Nov 16, 2005 6:00 am

Post by JeePee »

I figured that yesterday when i started up the mysql client from the start menu instead of going in from the regular command prompt. Thanks for clearing it up.

The only problem i'm having now is figuring out where i can download an updated client, i tried fresh installs of mysql 4 and 5 with included client but aparantly they come with an outdated client.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

Could it be that your php was compiled with a older version of mysql and you only got the new version running?
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

You go right to the source to download any of the files you need. http://www.mysql.com/
JeePee
Forum Newbie
Posts: 9
Joined: Wed Nov 16, 2005 6:00 am

Post by JeePee »

I got it working by creating an account with the old_password command. It then uses the old password encription wich is compatible with the older client i have running.

About downloading the files i need; I do not know wich files i need, there is no download that sais "mysql client update" or "mysql client ver.blabla". And i don't see anything that as far as i can tell could be it.

I got everything working now, that's what's most important, though it still will be nice if i can tackle this issue.

Anyways thanks for the help so far.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

It's easy to find the versions... Click on the download link on the main mysql link I posted for you. This is the download link... http://dev.mysql.com/downloads/

You will see links for version 5 http://dev.mysql.com/downloads/mysql/5.0.html and version 4.1 http://dev.mysql.com/downloads/mysql/4.1.html and older versions http://downloads.mysql.com/archives.php. Click on one of those links. The older versions links gives a list of versions from 3.xx to 5.xx. Click on something like the 4.1 versions on the older versions page and you get a list of 4.1 versions. Click on the version you are using and then find what you need from the list of files.
Post Reply