jgingras Posted June 19, 2005 Posted June 19, 2005 Hi! Im new to the php and mysql world and am trying to figure out the mysql_connect. In cPanel --> Manage mySQL, I have my database setup, named = username_dbname my user has all privileges for that database. I dont know what im missing. Here is my code. and the error that I get. code: $oconn=mysql_connect ("localhost", "username_", "******") or die ("I cannot connect to the database because: " . mysql_error()); mysql_select_db ("username_dbname"); error: mysql_connect(): Access denied for user: 'username_@localhost' (Using password: YES) in /home/username/public_html/admin/loginpost.php on line 5 For the error and code and changed my username to "username" and put *s instead of my password. I only have two php pages on my whole site, login.php which has a form to pass a username and password to connect to the site, (tblUsers in my db.) and this page. Am I missing another page? Am I missing other settings? Your help is much appreciated, Thanks, -Jacques Quote
GroovyFish Posted June 19, 2005 Posted June 19, 2005 Hi Jacques and welcome to the forum! It's hard to tell for sure from your example, but you should be using: cpanelusername_dbusername for the username cpanelusername_dbname for the database name Is that what you are using? Quote
TCH-Don Posted June 19, 2005 Posted June 19, 2005 Welcome to the forums Jacques The normal steps to use a database is in MySql create a database with a name like nuke create a user for the database like cmsuser with a password of xyz123 then add cmsuser to the nuke database The connect string should be in the form of $dbh=mysql_connect ("localhost", "cpanelname_cmsuser", "xyz123") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("cpanelname_nuke"); The most common error is forgetting to add the user to the database in MySql and will result in an error much like yours. Quote
jgingras Posted June 19, 2005 Author Posted June 19, 2005 Don and GroovyFish, thanks for that help. I was just using cpanelname_ as my username, so I added a new user and added it to the db and it worked great! Thanks for all your help. Glad to be on-board! -Jacques Quote
TCH-Don Posted June 19, 2005 Posted June 19, 2005 Glad you have working. let us know if you need more help Quote
TheMovieman Posted July 25, 2005 Posted July 25, 2005 Rather than starting a new post, I found this one and thought I'd ask it here. I haven't used MySQL Administrator in a while so I have forgotten the password. Since I am starting over with a database, I made a new one and added a user (for which I know the password) and gave it all privileges. However, when starting the MySQL Administrator, I type in the username cpanelname_username and the password (both I know are correct) but I get this error: MySQL Error Number: 1045 Access Denied to User: 'cpanelname_username@<stuff> us.da.qwest.net' (Using Password: YES) Now, the Server Host is correct and the port is 3306 (don't know if that makes a difference...). I had this working months ago and encountered a problem like this but cannot remember how I fixed it. BTW, I also created a new user and tried it there, but got the same error. Quote
TCH-Bruce Posted July 25, 2005 Posted July 25, 2005 Are you also accessing the database as cpanelname_database? Quote
TheMovieman Posted July 25, 2005 Posted July 25, 2005 (edited) I'm a little slow today, what do you mean? Edited July 25, 2005 by TheMovieman Quote
TweezerMan Posted July 26, 2005 Posted July 26, 2005 It sounds like you need to go into CPanel / MySQL Databases and add your computer's IP address under "Access Hosts" (near the bottom of the page) to grant your PC permission to access the MySQL server. Quote
TheMovieman Posted July 26, 2005 Posted July 26, 2005 (edited) Haha, what'd you? It did work! Thanks David! Edited July 26, 2005 by TheMovieman Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.