can not connect to database

Status
Not open for further replies.

dskamburapola15

New Member
Messages
4
Reaction score
0
Points
0
i tried to connect database from my web page with following code.

$host=\"localhost\";
$username=\"dsk123_test\";
$password=\"789\";
$db_name=\"dsk123_dsk\";

mysql_connect(\"$host\", \"$username\", \"$password\")or die(\"cannot connect to server\");
echo \"Host - Connected - OK <br><br>\";
mysql_select_db(\"$db_name\")or die(\"cannot select DB\");
echo \"Database - Connected - OK <br><br>\";

It display following messages.

Host - Connected - OK

cannot select DB

How to fix this.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Code:
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); 
echo "Host - Connected - OK <br><br>";
mysql_select_db("$db_name" , $link )or die("cannot select DB. Reason: " . mysql_error( $link ));
echo "Database - Connected - OK <br><br>";

Try the above edits to your code.
Always check the error message given by the DB .

You did remember to connect the specific user to the specific database in MySQL Databases and to give it ALL PRIVILIGES ?
 

dskamburapola15

New Member
Messages
4
Reaction score
0
Points
0
thanks. I tried your code.
But I got following error.

cannot select DB. Reason: Access denied for user 'dsk123_test'@'10.33.248.%' to database 'dsk123_dsk'

what to do.
 

stpvoice

Community Support Rep
Community Support
Messages
5,987
Reaction score
212
Points
63
Hello,

Did you add the user to the database as descalzo said before?
Are you trying to connect from a file on your x10 account?

Thanks.
 
Status
Not open for further replies.
Top