BrentonHale Posted December 27, 2009 Share Posted December 27, 2009 Hello, I'm using MySQL version 5.1.36, php version 5.3.0 and apache version 2.2.11. I am not able to connect to the database. I get the following error message. Could not connect to MySQL: Access denied for user 'username'@'localhost' (using password: YES) [<?php # Script 7.2 - mysql_connect.php // This file contains the database access information. // This file also establishes a connection to MySQL and selects the database. // Set the database access information as constants. DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error()); // Select the database. $mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error()); ?>/code] I don't use a password when I sign into the MySQL console. Could someone please tell me how to resolve this issue and what code I need to use? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/186413-unable-to-connect-to-database-access-denied/ Share on other sites More sharing options...
bruceleejr Posted December 27, 2009 Share Posted December 27, 2009 Replace bold with your credentials DEFINE ('DB_USER', 'YOUR DATABASE USERNAME'); DEFINE ('DB_PASSWORD', 'YOUR PASSWORD'); DEFINE ('DB_HOST', 'YOUR MYSQL HOST'); DEFINE ('DB_NAME', 'YOUR DATABASE NAME'); You get these from your webhost Quote Link to comment https://forums.phpfreaks.com/topic/186413-unable-to-connect-to-database-access-denied/#findComment-984396 Share on other sites More sharing options...
BrentonHale Posted December 27, 2009 Author Share Posted December 27, 2009 Replace bold with your credentials DEFINE ('DB_USER', 'YOUR DATABASE USERNAME'); DEFINE ('DB_PASSWORD', 'YOUR PASSWORD'); DEFINE ('DB_HOST', 'YOUR MYSQL HOST'); DEFINE ('DB_NAME', 'YOUR DATABASE NAME'); You get these from your webhost Okay, that's what they were using in this book. Let me explain: the database username is: brenton the password is: password mysql host is: localhost (i don't have web hosting yet) database name is: sitename Now, I'm getting this error message: Notice: Undefined variable: mysql_select_db in C:\wamp\www\mysql_connect.php on line 16Fatal error: Function name must be a string in C:\wamp\www\mysql_connect.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/186413-unable-to-connect-to-database-access-denied/#findComment-984397 Share on other sites More sharing options...
fenway Posted December 28, 2009 Share Posted December 28, 2009 That's a PHP error. Quote Link to comment https://forums.phpfreaks.com/topic/186413-unable-to-connect-to-database-access-denied/#findComment-984718 Share on other sites More sharing options...
Maq Posted December 28, 2009 Share Posted December 28, 2009 Now, I'm getting this error message: Notice: Undefined variable: mysql_select_db in C:\wamp\www\mysql_connect.php on line 16Fatal error: Function name must be a string in C:\wamp\www\mysql_connect.php on line 16 That's because "mysql_select_db()" is a function. Remove the dollar sign. Quote Link to comment https://forums.phpfreaks.com/topic/186413-unable-to-connect-to-database-access-denied/#findComment-984901 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.