Help - Search - Members - Calendar
Full Version: SQL connection string in php
Hostony Board > General Support > PHP/MySQL
Saad
I keep getting this error and I don't know why, I'm bretty sure I get the user name and password correct. I would appreciate it if someone have a look at the code at the bottom.

http://www.asooomy.com/jeddah.tv/MN5/index4.php

" Unable to select database because: Access denied for user 'saad_xxxxx'@'localhost' to database 'saad_MN5' "



#------------------------------------------------------------------------------

<?php

$dbhost = "localhost";
$dbname = "'saad_MN5";
$dbuser = "saad_xxxxx";
$dbpass = "xxxxxx";

$conn=mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error());

mysql_select_db($dbname) or die("Unable to select database cause: " . mysql_error());

$query = "SELECT * FROM MN5";
$result = mysql_query($query) or die(mysql_error());

mysql_close($conn);
?>
JasonJones
If thats a straight paste of your code, look at the dbname variable it holds the answer.
Saad
Thanks Jason for pointing this out. This is the modified code and still giving me the same error.

" Unable to select database because: Access denied for user 'saad_xxxxx'@'localhost' to database 'saad_MN5' "

<html>
<head>
<title>My First PHP Page</title>
</head>
<body>

<?php

#
#------------------------ [ SQL Connection String] ------------------------------
#
$dbhost = "localhost";
$dbname = "saad_MN5";
$dbuser = "saad_xxxxx";
$dbpass = "xxxxxx";

$conn=mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error());

mysql_select_db($dbname) or die("Unable to select database because: " . mysql_error());
#---------------------------------------- --------------------------------------------

$query = "SELECT * FROM MN5";
#$result = mysql_query($query) or die(mysql_error());






mysql_close($conn);

?>

</body>
</html>
MartinB
you add the user to the database with the correct rights ?

1) Create the database
2) Create the username
3) Assign The username to the database with the correct rights.

If you are using cpanel, you have on the mysql databases section, in the same page with the "Add db" form and the "Add user" form, you have an "Add user to Db" form.
Saad
mblendinger,

Now, It is working. Thanks alot, I just realized that I have missed step#3in your response. I apprecate it.
MartinB
QUOTE(Saad @ Dec 4 2005, 12:28 PM)
mblendinger,

Now, It is working. Thanks alot, I just realized that I have missed step#3in your response. I apprecate it.
*


I think that.
Glad to help you wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.
IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here