Jump to content

Recommended Posts

I had IIS on my laptop -> desinstalled and cleaned the register with Ccleaner, also did it by hand whats left of it, also deleted every trace left on disk C.

I had skype on my laptop -> desinstalled and cleaned the register with Ccleaner, also did it by hand whats left of it, also deleted every trace left on disk C.

I restarted my laptop.

 

I installed WAMP, the latest version available today.

 

The wamp icon stayed orange when I activated the wampserver and went never into green.

In httpd.confIg I changed the port  into  Listen 8081, I restarted WAMPserver and the icon went finally green. 

ONLY then I could open phpMyAdmin en was able to open localhost:8081.

 

Now I wanted to test the connection :

<?php
$db_host = "localhost";
$db_user= "root@localhost";
$db_pass = '';
$db_name = "projecteasywebsite";
    

//connect to mysql database server
mysql_connect($db_host, $db_user, $db_pass) or die (mysql_error());
echo "Successfully connected to MySQL Database!<br><br>";

//Select Database
mysql_select_db($db_naam) or die (mysql_error());
echo '<h2>Successfully selected ' . $db_name . ' database!</h2>';
?>

It gave as a result :

Successfully connected to MySQL Database!

 

Access denied for user ''@'localhost' to database 'projecteasywebsite'

 

 

I've been searchin for houres now on the net and tried different things, I also created a new user in PHPMYADMIN and got the same results back -> Access denied for ...

 

I even changed the hostname -> $db_host = "localhost:8081";  and  the page kept buzzy searching for a connection or... So no result was brought from localhost:8081

 

So why did'n the icon turned into green the first time ?

Why did I had to change the port to 8081  for having acces to PHPMYADMIN and localhost:8081 ?

 

The problem is in my opinion related to this. But I have no clue whatsoever ! And I searched for houres but all solutions I found didn't helped.

 

Are there hard core people here who can help me please ?

 

Link to comment
https://forums.phpfreaks.com/topic/261811-wamp-acces-denied-for-user/
Share on other sites

In this type of setup all you need to do to connect to mysql is provide the host of 'localhost'.  This worked, as shown in your script.

 

MySQL does listen on a well known port, but that is nothing you need to be concerned about.  Don't confuse the php script connecting to the mysql database with a web application like phpmyadmin.  Web apps listen on port 80 by default, but in setups like this, they use a different port for administration web applications, just to keep things simple for people.  Phpmyadmin is nothing other than a php script that connects to mysql in the same way your php script connects to it. 

 

Now let's focus on what your mistake was....

 

 

//connect to mysql database server
mysql_connect($db_host, $db_user, $db_pass) or die (mysql_error());
echo "Successfully connected to MySQL Database!

";

//Select Database
mysql_select_db($db_naam) or die (mysql_error());

 

Notice that your code told you it connected fine.  It was on the mysql_select_db call that you got an error.

 

Hmm, let's look at your variables: 

 

$db_name = "projecteasywebsite";

 

And you tried to select the database with this:

 

mysql_select_db($db_naam) or die (mysql_error());

 

See the problem with the database name variable?

 

 

Yes indeed, that was the error at the end. i have been staring too long at those codes I guess. But in the beginning there was really something strange going on with the wamp setup. But now it works and that's the point. So thank you for that.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.