Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 PHP MySQL DB Issue - cant connect?
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DanShadow




PostPosted: Fri Oct 01, 2010 9:24 pm   Post subject: PHP MySQL DB Issue - cant connect?

Hey all.
The issue i'm having, is that every time I try to connect to my MySQL database I get a permission error.

My code is:
Code wrote:

<?php

$clientTBname="ClientTable";
$userTBname="UserTable";
$scheduleTBname="ScheduleTable";

$hostname="localhost";

$dbname="dbname";
$username="dbadmin";
$password="dbpassword";
$connection="";

echo "Connecting to database...<br>";

$connection=mysql_connect($localhost, $username, $password);

if (!($connection) || ($connection == '')) {
echo "Failed to connect to database.";
exit();
} else {
echo "Success!<br><br>";
}


Every time I run this, I get this error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'dbadmin'@'localhost' (using password: YES) in /home/dsp54/public_html/CreateTables.php on line 28

I've tried changing 'localhost' to the server name & MySQL port, but I get the same error.

Anybody encountered anything like this before?
I'm using the same code as I have on a server I worked with a DB on years ago, and it worked back then... so im guessing the issue is with the DB server/host.. but can't seem to figure it out.

Thanks!
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Fri Oct 01, 2010 9:36 pm   Post subject: RE:PHP MySQL DB Issue - cant connect?

The username and password you used years ago probably wont be the same, unless you had the same MySQL server running for years.

If you didn't change the password, use the username 'root' with no password. This is fine as long as the database is not publicly accessible; if it is, change the password to something secure, and definitely consider creating users that don't have permission to do stuff they shouldn't (creating new tables, deleting tables, &c).
DanShadow




PostPosted: Fri Oct 01, 2010 9:39 pm   Post subject: RE:PHP MySQL DB Issue - cant connect?

... lol, I know Razz.

Thanks for the help anyway.

I ended up fixing the issue, turned out I made a typo when I set up my user account that was assigned to that DB, haha.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: