Connecting Tech Pros Worldwide Forums | Help | Site Map

Unable to connect to MySQL database!

Newbie
 
Join Date: Sep 2007
Posts: 8
#1: Sep 22 '07
Im new user of PHP and MySQL.

I tried to use a script package for my web. I'd created a database.
And my connection scripts are as follow;

[PHP]<?php

$mysql_host="localhost";

$mysql_username="hidden";

$mysql_password="hidden";

$mysql_database="hidden";

$site_name="My Share Host"; //name of your site

$site_url="http://hidden"; //full url of your site without trailing slash!

//------------------------------------------------------------

//-----------Do not modify anything under this line!----------

//------------------------------------------------------------



$dbhandle=mysql_connect($mysql_host,$mysql_usernam e,$mysql_password);

@mysql_select_db($mysql_database) or die("<div align=\"center\">Unable to connect to MySQL database!</div>");

$query="SELECT server FROM ftp_connection WHERE 1";

$result=mysql_query($query);

$ftp_server=@mysql_result($result,0);

...and some other functions here...



mysql_close($link);

?>[/PHP]


It gives error:


Unable to connect to MySQL database!

Someone please guide me.

Thank you very much.

Newbie
 
Join Date: Sep 2007
Posts: 8
#2: Sep 22 '07

re: Unable to connect to MySQL database!


when i entering from another computer....

this is the error message:

锘?div align="center">Unable to connect to MySQL database!
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#3: Sep 22 '07

re: Unable to connect to MySQL database!


Quote:

Originally Posted by malaysiauser

when i entering from another computer....

this is the error message:

锘?div align="center">Unable to connect to MySQL database!

Are you able to connect to MySQL from the console using those details?
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#4: Sep 22 '07

re: Unable to connect to MySQL database!


Do not use words like HELP PLEASE in title. Kindly use CODE tags when posting source code.

Use mysql_error() when connecting to DB to know the correct error. e.g.

[PHP]$dbhandle=mysql_connect($mysql_host,$mysql_usernam e,$mysql_password) or die("Error: ".mysql_error());

mysql_select_db($mysql_database) or die("<div align=\"center\">Unable to connect to MySQL database! Error: ".mysql_error()."</div>");[/PHP]
After using this code, what error do you get?
Newbie
 
Join Date: Sep 2007
Posts: 8
#5: Sep 23 '07

re: Unable to connect to MySQL database!


pls check my site www.digimage,info

the error is unable to connect to mysql
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#6: Sep 23 '07

re: Unable to connect to MySQL database!


Did you use mysql_error() when connecting to database as I suggested in my previous post?
Newbie
 
Join Date: Sep 2007
Posts: 8
#7: Sep 24 '07

re: Unable to connect to MySQL database!


Unable to connect to MySQL database! Error: Access denied for user 'digimage'@'localhost' to database 'filehost'

i'd created a database "filehost" with a username and password.
So in my php setting i use that username and password.
And for that user i select 'allow all'. But i still getting access denied.
Im using cpanel.

tq sir..
Newbie
 
Join Date: Sep 2007
Posts: 8
#8: Sep 24 '07

re: Unable to connect to MySQL database!


i try to add another user and got this error;


Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'digi'@'localhost' (using password: YES) in /home/digimage/public_html/settings.inc.php on line 23
Error: Access denied for user 'digi'@'localhost' (using password: YES)


im using cpanel to manage my MySQL database.

any idea?
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#9: Sep 24 '07

re: Unable to connect to MySQL database!


Quote:

Originally Posted by malaysiauser

Unable to connect to MySQL database! Error: Access denied for user 'digimage'@'localhost' to database 'filehost'

i'd created a database "filehost" with a username and password.
So in my php setting i use that username and password.
And for that user i select 'allow all'. But i still getting access denied.
Im using cpanel.

tq sir..

In CPanel, username and database are started with your hosting account username. e.g. if you have created a user named 'digimage' then it should be something like hostingusername_digimage and the same with the database name.
Reply