Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Access Denied' to MySQL database - a simple problem for an expert

Status
Not open for further replies.

codequirks

Programmer
Nov 18, 2008
11
GB
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:

Code:
----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);
?>
 
localhost and 127.0.0.1 are not the same for MySQL. If you granted access to phpaccess@'%', you should also give access to phpaccess@localhost. Localhost does not use a network in MySQL.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Don

Thanks very much, changed it and it worked a treat - although I'd have never ever found that without your comment

Ta
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank DonQuichote
for this valuable post![/navy]


at the bottom of DonQuichote's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top