acallahan Posted December 6, 2008 Share Posted December 6, 2008 I am working on a practice project for school, so I would prefer a response to my question that would help me learn what I am doing wrong as opposed to simply giving me the answer, but I am on a tight deadline for getting the project completed. The error states that Notice: Could not connect to MySQL: Access denied for user 'myuser'@'localhost' (using password: YES) in /home/acallaha/public_html/Corporanker/includes/connection.php on line 22 I have set up the database using a MySQL database wizard with the correct username and password, using localhost as the host, and making sure the database name was correct. I also made sure the user had all priviledges. My connection.php script resembles what is below: <?php $db_user = 'myuser'; $db_password = 'mypassword'; $db_host = 'localhost'; $db_name = 'mydatabasename'; $connection = @mysqli_connect($db_host, $db_user, $db_password, $db_name); if (!$connecton) { trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error(); } ?> Can anyone see anything obvious as to why the user would be denied access? I can't start troubleshooting any other error until I get past the connection error! Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/ Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 Just checking are you meant to be using mysqli?? I see a lot of people using this when they should be using mysql Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707865 Share on other sites More sharing options...
waynew Posted December 6, 2008 Share Posted December 6, 2008 Notice: Could not connect to MySQL: Access denied for user 'myuser'@'localhost' (using password: YES) in /home/acallaha/public_html/Corporanker/includes/connection.php on line 22 It means that your database connection details are wrong. Is your username correct? Usually the default MYSQL username is "root"... assuming that you've just installed MySQL. The password on default is blank. Which means that it's $password = "" Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707868 Share on other sites More sharing options...
waynew Posted December 6, 2008 Share Posted December 6, 2008 Just checking are you meant to be using mysqli?? I see a lot of people using this when they should be using mysql Mysqli is better. More secure and better for performance. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707872 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 The textbook example uses mysqli. We're using free hosting sites to display our projects, so I used the zendfree free hosting. I didn't need to install MySQL. I just needed to create the database and the table(s), set up the user, password, priviledges, etc. I triple checked that all the spellings and cases matched up. They do. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707883 Share on other sites More sharing options...
gevans Posted December 6, 2008 Share Posted December 6, 2008 try this <?php $db_user = 'myuser'; $db_password = 'mypassword'; $db_host = 'localhost'; $db_name = 'mydatabasename'; $connection = mysql_connect($db_host, $db_user, $db_password, $db_name); if (!$connecton) { trigger_error ('Could not connect to MySQL: ' . mysql_connect_error(); } ?> With all your details added back in Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707889 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 When I try the above script, I get the following error... Fatal error: Call to undefined function mysql_connect_error() in /home/acallaha/public_html/Corporanker/includes/connection.php on line 22 Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707910 Share on other sites More sharing options...
premiso Posted December 6, 2008 Share Posted December 6, 2008 mysql_error is what it should be, not mysql_connect_error. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707913 Share on other sites More sharing options...
Noskiw Posted December 6, 2008 Share Posted December 6, 2008 I am working on a practice project for school, so I would prefer a response to my question that would help me learn what I am doing wrong as opposed to simply giving me the answer, but I am on a tight deadline for getting the project completed. The error states that Notice: Could not connect to MySQL: Access denied for user 'myuser'@'localhost' (using password: YES) in /home/acallaha/public_html/Corporanker/includes/connection.php on line 22 I have set up the database using a MySQL database wizard with the correct username and password, using localhost as the host, and making sure the database name was correct. I also made sure the user had all priviledges. My connection.php script resembles what is below: <?php $db_user = 'myuser'; $db_password = 'mypassword'; $db_host = 'localhost'; $db_name = 'mydatabasename'; $connection = @mysqli_connect($db_host, $db_user, $db_password, $db_name); if (!$connecton) { trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error(); } ?> Can anyone see anything obvious as to why the user would be denied access? I can't start troubleshooting any other error until I get past the connection error! much simpler version <?php $con = mysql_connect(localhost, "dbname here", "dbpass here"); $db = mysql_select_db(dbname here, $con); if(!$con){ echo "ERROR: could not connect to database!\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707914 Share on other sites More sharing options...
premiso Posted December 6, 2008 Share Posted December 6, 2008 Not to dis you ghostrider, just modifying your code to be more logical, cause if you are not connected, then there is no reason to select the DB. Also that code tells nothing about the error, IE why it would not connect. <?php $con = mysql_connect(localhost, "dbname here", "dbpass here"); if(!$con){ die( "ERROR: could not connect to database!<br /> With ERROR: " . mysql_error()); } $db = mysql_select_db(dbname here, $con); ?> So if no connection kill the script and tell them why it was killed. Good for development scenarios so you can see exactly what is going wrong, etc. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707916 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 The first suggestion gets me back to the original error message. The second suggestion gives me this error: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'acallaha'@'localhost' (using password: YES) in /home/acallaha/public_html/Corporanker/includes/connection.php on line 2 Database connection failed: Access denied for user 'acallaha'@'localhost' (using password: YES) Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707917 Share on other sites More sharing options...
Noskiw Posted December 6, 2008 Share Posted December 6, 2008 remove the password, insert root in the dbusername bit and leave the dbpass bit empty so it should be <?php $con = mysql_connect(localhost, "root", ""); if(!$con){ die( "ERROR: could not connect to database!<br /> With ERROR: " . mysql_error()); } $db = mysql_select_db(insert dbname here, $con); ?> BTW premiso, you were right. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707921 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /home/acallaha/public_html/Corporanker/includes/connection.php on line 2 Database connection failed: Access denied for user 'root'@'localhost' (using password: NO) Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707923 Share on other sites More sharing options...
premiso Posted December 6, 2008 Share Posted December 6, 2008 are you sure you created a user in the database? root should work by default unless that was modified. Check your database and make sure it allows for that username/password combo and or reset it so it matches what you want. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707924 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2008 Share Posted December 6, 2008 Shared hosting is not going to allow access using the "root" user. ----------------------------------------- Are you sure the mysql database host is localhost? There may in fact be a mysql server running on localhost, but I would bet that when you created your database/user/password that the host name or IP address displayed on the relevant screens was something like mysqlx.somedomain.com and not localhost. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707925 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 I tried creating a new user to see what was displayed. appended to the url in the browser was /frontend/x3/sql/ Does that help any? Prior to zendFree being offline for the past three days, localhost worked, at least in my other database/project. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707930 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2008 Share Posted December 6, 2008 So what username/database name did you use in your other projects. The following is a extract from a Tutorial on their forum that indicates that you must add your cpanelusername as part of the user and database names - The dbusername will be "cpanelusername_Dbusername" and the DB name will be "cpanelusername_dbname" Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707933 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 The other database is acallaha_Liberia. The connection scripts works with a database name of Liberia. The username in the other connection script works without the acallaha_ in front of it, also. http://acallaha.zendfree.com/acallaha/Welcome.php is the old project. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707947 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2008 Share Posted December 6, 2008 I recommend you try your old project to see if it still works. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707952 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 I checked it prior to posting the link.... Additionally, it is the same user being used for both databases. Access is only denied for one. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707957 Share on other sites More sharing options...
acallahan Posted December 6, 2008 Author Share Posted December 6, 2008 I started over with it..copy and pasted the connection.php from the old project and changed out the database name. There must be a typo in the original one I posted because it seems to work fine now. Quote Link to comment https://forums.phpfreaks.com/topic/135814-connection-error-in-practice-project/#findComment-707968 Share on other sites More sharing options...
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.