Forum Moderators: coopster

Message Too Old, No Replies

server tests wrong username & password

Is my mysq._connect code wrong?

         

mlkarie

7:23 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Hi

I'm a newbie when it comes to testing PHP/MySQL files on a remote server.

Have battled through some problems and solved them; however, the following leaves me stumped:

My code is:

$mysql_database="my_database";
$mysql_username="my_user";
$mysql_password="my_password";

$link = mysql_connect($mysql_database,"33.66.99.39",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db($mysql_database,$link) or die ("Unable to select database");

The server is happy with my host IP, but returns an error:

Warning: mysql_connect(): Access denied for user: '33.66.99.39@hostserver.domain_name.net' (Using password: YES) in php_filename

In other words, it makes up a username from the IP address and server domain name, and doesn't seem to test the username and password that's specified in my PHP file.

What could be the reason? Is there something wrong with my code?

Thanks for the help
mlkarie

Distel

7:38 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



I could be wrong, but I think that in the beginning of your mysql_connect statement, $mysql_database should not be there. i.e., it should be:

$link = mysql_connect("33.66.99.39",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");

Birdman

9:30 pm on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On my host's server, you have to add your main account username to the mysql username and the mysql database name.

$my_host_username = "hostusername";
$my_mysql_username = "mysqlusername";
$my_mysql_password = "pswd";
$mysql_database="my_database";
$link = mysql_connect("localhost",{$my_host_username}_{$my_mysql_username},$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db({$my_host_username}_{$mysql_database},$link) or die ("Unable to select database");

In other words, the username should really be "hostusername_mysqlusername" and your database should be the same.

This is how it works on my server, anyway.

coopster

1:48 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've also seen this happen when the server does not require the password. You could try:

$mysql_password='';

...or, contact the remote server admin and get the exact connection syntax requirements ;)

shady

2:08 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Hi mlkarie

Why are you using an ip address? Is the mysql database on a different IP to the application?

If so, does the application IP have access the the DB (this can be easily defined in Cpanel if you have it)

Birdman

2:24 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



..or, contact the remote server admin and get the exact connection syntax requirements

Good idea. Or, if you have phpmyAdmin, you can get the PHP connection string right there.

Definately try using "localhost", instead of ip. Unless you are trying to connect to a remote server(refer to msg #5).

mlkarie

4:18 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Distel, I constructed my connection statement by following the syntax rules explained in the MySQL documentation. But maybe their MySQL version has a different syntax. (?)

Birdman, your solution might be correct; I'll probably have to contact the server administrator to find out if they require the host username as well. I can't use localhost here, as already indicated by the server administrator.

Coopster, the database that I'm trying to connect to, does require a password.

Shady, the IP address is provided on the server's control panel for use to connect to the host.

Could it be a problem of different syntax on the MySQL version on their server? I was hoping to solve this without contacting the server administrator again. They are going to start thinking that I'm really dumb.

mlkarie

5:45 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Here's the solution (i.e. database shouldn't have been a paramenter in the mysql_connect command):

$link = mysql_connect("33.66.99.39",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db($mysql_database,$link) or die ("Unable to select database");

BTW, now that I'm through to the server, it says "Unable to select database".

It's tough being a newbie...but what do they say? If you can't stand the heat in the kitchen, get out. I'm staying in the kitchen...

mlkarie

5:47 am on Nov 25, 2003 (gmt 0)

10+ Year Member



Sorry, forgot to say:

Thanks, Distel :=)

Distel

10:59 am on Nov 25, 2003 (gmt 0)

10+ Year Member



No probs :)

coopster

11:01 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mlkarie,
Have a look at the mini-tutorial in post #5 written by jatar_k in this thread regarding Basics of extracting data from MySQL using PHP [webmasterworld.com]. It's a great start!