PDA

View Full Version : Connecting To Mysql With Php Problem


airvan00
08-30-2004, 02:29 PM
I'm very new to PHP and mySql and I'm having problems connecting to mySql (as the topic would suggest :rolleyes: ). I think my problem is just syntax, but I would appreciate any help I can get that will get my project rolling and I hope there isn't a problem with me posting actually users and passwords for my mysql database that I created just for connecting purposes.

Ok, I created the database in DirectAdmin using the MySQL Management link and this is what I successfully created and updated the password to something very simple:

Details

User username_admin has been updated. Use the following values:

Database: username_request
Host: localhost
Username: username_admin
Password: password

So now, I created a "test.php" page to try and connect to it with the following PHP codes:

<?php

// mysql Database info
$host="localhost";
$user="username_admin";
$password="test";

$connection = mysql_connect($host,$user,$password);

?>

Then, I go and try to load my page at http://xxx.xxx.xxx.xxx/test.php and I get the following connect error:

Warning: mysql_connect(): Access denied for user: 'username_admin@localhost' (Using password: YES) in /home/ampacm00/xxx.xxx.xxx.xxx/public_html/test.php on line 8

Is there something wrong with my syntax or is my "mysql_userid" and "password" just incorrect?

Please help, thanks in advance.

Herbster
08-30-2004, 02:44 PM
This is the syntax I use:

$link = mysql_connect("$mysql_host", "$mysql_user", "$mysql_password")
or die("Could not connect");

You say "Password: password " and then you specify the password as "$password="test";". ??

P.S. I wouldn't post actual usernames or passwords in a public forum.

airvan00
08-30-2004, 05:26 PM
Thanks for the quick response. Sorry for the display of the actually database information. I do plan to delete it and start over, but I'm just trying to make a connection to it for now.

I did try the code that you put up i still get the same mysql error message.

Warning: mysql_connect(): Access denied for user: username_admin@localhost' (Using password: YES) in /home/xxx/domains/xxx.xxx.xxx.xxx/public_html/test.php on line 8

My question is, on the mysql management application, where it list your database info:

eg.
Database: username_request
Host: localhost
Username: username_admin
Password: test

This is the username and password that you would put in the $user and $password variable, correct? According the error, I'm just denied access for some reason. Could it be something with the permissions or where I have this test.php file at?

Herbster
08-31-2004, 07:55 AM
You might have your test script echo the password variable to the screen to verify that the correct parameter is being passed to mysql_connect().

thevillageinn
08-31-2004, 08:46 PM
that's a good suggestion Herbster, and a method of debugging which I've frequently employed when programming. If you are getting errors on something which should work, check to make sure that your variables are holding the values you are expecting them to...