codequirks Posted October 25, 2009 Share Posted October 25, 2009 Hi there I am a little new to php having been working in the dark world of databases for many years. I am in the process of creating my first website but whilst the php and the database stuff work great I cannot get the two to talk. The error is: DB connection failed: Access denied for user 'phpaccess'@'localhost' (using password: YES). I think this is likely just a small config or privilege tweak - can any of you experts help? The user is 'phpaccess'@'%' and only has select privilege on db_mydatabase - nothing else As always thanks for your time in advance and code below, php 5.2, MySQL 5.1: ----Test PHP File <HEAD><TITLE>HTML, PHP, MySQL Test Page</TITLE></HEAD> <BODY> <?PHP //Run phpinfo to make sure MySQL is loaded and working phpinfo(); //Set up database connection parameters $myServer = "127.0.0.1"; $myUser = "phpaccess"; $myPass = "phppassw0rd"; $myDB = "db_mydatabase"; //Open mySQL connection with all errors reported ini_set('display_errors', 1); error_reporting(E_ALL); $connection = mysql_connect($myServer, $myUser, $myPass); if (!$connection) { die("DB connection failed: " . mysql_error()); } //Activate database and then query the table $activedb = mysql_select_db($myDB, $connection) or die ("Couldn't open database"); $query = mssql_init("SELECT * FROM `tb_users`", $connection); $result = mssql_execute($query); echo "success"; mysql_close($connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/178931-solved-access-denied-to-mysql-database-a-simple-problem-for-an-expert/ Share on other sites More sharing options...
cbolson Posted October 25, 2009 Share Posted October 25, 2009 Try changing $myServer = "127.0.0.1"; to $myServer = "localhost"; Chris Quote Link to comment https://forums.phpfreaks.com/topic/178931-solved-access-denied-to-mysql-database-a-simple-problem-for-an-expert/#findComment-944015 Share on other sites More sharing options...
Mchl Posted October 25, 2009 Share Posted October 25, 2009 Try giving the user ALL privileges and see if problem goes away or stays. Quote Link to comment https://forums.phpfreaks.com/topic/178931-solved-access-denied-to-mysql-database-a-simple-problem-for-an-expert/#findComment-944017 Share on other sites More sharing options...
codequirks Posted October 25, 2009 Author Share Posted October 25, 2009 Ok - We have a solution: Thanks Mr Bolson - I did have to change the server to localhost but also had to change the users login from 'phpaccess'@'%' to 'phpaccess'@'localhost' And then it all suddenly worked! Quote Link to comment https://forums.phpfreaks.com/topic/178931-solved-access-denied-to-mysql-database-a-simple-problem-for-an-expert/#findComment-944086 Share on other sites More sharing options...
Mchl Posted October 25, 2009 Share Posted October 25, 2009 It was already trying to connect to localhost, so it was probably a username issue. Quote Link to comment https://forums.phpfreaks.com/topic/178931-solved-access-denied-to-mysql-database-a-simple-problem-for-an-expert/#findComment-944096 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.