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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to mysql db

Status
Not open for further replies.

irisha2

Technical User
Feb 19, 2002
9
US
Please help with database connection.
I'm attempting to connect to mysql db from php for the first time, and I keep getting the following error:

Warning: Access denied for user: 'mysql@mysysname.org' (Using password: YES) in /home/user/public_html/main.php on line 65

Error connecting db server

The following code is included in my php file:

$HOST = "mysysname:3306";
$ID = "mysql";
$PWD = "mypasswd";

$db = mysql_pconnect($HOST,$ID,$PWD);

if (!$db) echo "Error connecting db server";
else
echo "Connected to db server";

if (!mysql_select_db("DB_name",$db))
{
echo "Error selecting database";
exit;
}
else
{
mysql_select_db('DB_name',$db);
}

$query = "SELECT fname, lname FROM main WHERE fname = $fname AND
lname = $lname";
@$result = mysql_query($query,$db);
if ($result)
{
echo "Query error! - A user with this exact first and last name already exists.";
}
else
{
$query = "INSERT into main values ($fname, $lname, $gender, $dob, $race, $cntry_birth, $height, $metric1, $weight, $metric2, $ecolor, $hcolor, $status, $age)";
}

I'm not able to connect to db.
I verified that the password is correct but I'm not sure about syntax or commands used.

Any help would be much appreciated.

Thanks in advance.

Irina
 
I would it is your
Code:
$HOST = "mysysname:3306";
$ID = "mysql";
$PWD = "mypasswd";

Are you sure about using port 3306? Have you tried using just plain old "localhost"? One of these three variables has to be wrong. -gerrygerry
Go To
 
Hi Gerry,

I've tried localhost, my static IP address, my actual hostname, etc...

The PHP manual states that the server name might also need to be suffixed with the port number...

3306 is the port number listed in my /etc/services file...

Now, having said that, MySql and Sybase are quite similar...

In Sybase, I have an actual machine name, a virtual server name and a database name...

For Sybase, the command would be something like this:

sybase_connect(rk_1492,mysql,mypasswd);

Now, the rk_1492 is NOT the actual machine name, but the name of a "virtual" server...

In MySql, I have NOT found anyplace or reason to setup a "virtual" server...

Is this correct?

Am I supposed to setup a "virtual" server someplace?

In Sybase, you can have multiple "virtual" servers running, each with multiple databases...

In Sybase, there's an "interfaces" file, that contains the name of each virtual server, along with it's associated port number...

Is there such a file in MySql?

I know there's a default configuration file; /etc/my.cnf...

And I believe it's setup properly...

But... Then again, this is my first time to connect PHP to a database, any database...

(Actually, I'm trying to connect PHP to both MySql and Sybase, as a learning experience...)

The sybase_connect command makes more sense to me, because it lists a "virtual" server name (which I'm familiar with), and the interfaces file (which I'm also familiar with)...

Again, any help in resolving my connectivity issue would be much appreciated...

Irina
 
Hmmmm... I am not experienced enough with server configuration to help out with this one. Sorry!

I do believe that you can put a virtual server in for the host argument to mysql_connect(); but again, I am not experienced enough. Have you tried using mysql_connect() instead of mysql_pconnect()?

Sorry again... good luck! There are all sorts of php giants in this forum that will help u out. -gerrygerry
Go To
 
Are you sure the user mysql with password mypasswd at host mysysname has been added to the user table with the appropriate permissions using the grant command?
 
Thanks!

I resolved this problem... You're wright. It was a permission issue (wrong password in user table).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top