Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

Bitnami WAMP - phpmyAdmin - Access denied for user 'root'@'localhost' (using password: YES)

I am using the Bitnami WAMP and have tested the connection to a db with a small program.  It worked fine.  I load up a more complex program and I get the

mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)

I have a screenshot showing that the privileges for all users is yes. The only difference between the two is that I am using this for the connection

DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '#######');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'ecommerce');

// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Set the character set:
mysqli_set_charset($dbc, 'utf8');
User generated image
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Assuming you are running that on the same machine that the WAMP is on, the only reason that would fail is if you typed the password wrong.
Avatar of JohnMac328

ASKER

Same one as the test db that connects with no problem.
Sorry, that doesn't make any sense.  If the two scripts act different it is because there is a difference.
Here is the first
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="######"; // Mysql password
$db_name="ecommerce"; // Database name


Here is the second
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '######');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'ecommerce');

// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

The only difference is the connection mysqli_connect  as opposed to
mysql_connect("$host", "$username", "$password")or die("cannot connect");

I know it does not make sense - that's why I came here :)
Here's the page http://php.net/manual/en/mysqli.construct.php for 'mysqli_connect '.  Try doing it inline like in the procedural example instead of using DEFINE.  Here's the page for DEFINE: http://php.net/manual/en/function.define.php
Shows a syntax error with this line

$dbc = mysqli_connect ([ string $host = ini_get("localhost") [, string $username = ini_get("root") [, string $passwd = ini_get("######") [, string $dbname = "ecommerce" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
Yes, it would.  There are a lot of extra '[]' characters in that line that are supposed to tell you that some of the parameters are optional.

I tried your original code above with the DEFINE statements using my own info in my WAMP installation and, after I cleaned up my errors, it worked fine.
Ok then the only other thing that is different is that the code is in a file that is outside of the root - here is how it connects

define ('BASE_URI', '../../ecommerce2securefiles/');
define ('BASE_URL', 'http://localhost:8080/ecommerce/');
define ('MYSQL', BASE_URI . 'mysql.inc.php');
I suggest you do a simple test file inside the root that includes all the needed info and does not depend on any of those 'defines'.  You can always erase it when you are done.  But that will tell you if the 'defines' are part of the problem.
Seems like it - I just did this and it connects

$Connection = mysql_connect("localhost", "root", "######") or die("Could not connect");
   $dbc = mysql_select_db("ecommerce", $Connection) or die("Could not select database");

But it bombs in some code in the header that once again has a problem with mysqli

mysqli_query() expects parameter 1 to be mysqli, boolean given

Here is the code part - it bombs on the $r line
$q = 'SELECT * FROM categories ORDER BY category';
$r = mysqli_query($dbc, $q);
On any given connection, you have use either 'mysql' or 'mysqli'.  You can not use both together.  They are completely different drivers and methods and they do Not work together.
I am testing with my small program.  I changed what I can see from mysql to mysql.  It is connecting but not displaying the records.  Can you see where I have not correctly changed from mysql to mysqli?  I am new to php

Thanks

//$host="localhost"; // Host name 
//$username="root"; // Mysql username 
//$password="######"; // Mysql password 
//$db_name="maxibillions"; // Database name 
//$tbl_name="employee_data"; // Table name 

// Connect to server and select databse.
//mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
//mysql_select_db("$db_name")or die("cannot select DB");

DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '######');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'maxibillions');

// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);



//$q = 'SELECT * FROM categories ORDER BY category';
//$r = mysqli_query($dbc, $q);

$sql="SELECT * FROM employee_data WHERE active_account = '1'";
$result=mysqli_query($dbc, $sql);

//$count=mysql_num_rows($result);
 $rowcount=mysqli_num_rows($result);
?>
<html>
<body>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><center>
<strong>Delete multiple Records in MySQL</strong> </center></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
</tr>
<?php
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $row['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['first_name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['last_name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['email_name']; ?></td>
</tr>
<?php
}
?>

<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete">
<input name="delete" type="submit" id="delete" value="Refresh" onClick="<meta http-equiv=\"refresh\" content=\"0;URL=del.php\">
</td>
</tr>

</table>
</form>
</td>
</tr>
</table>
</body>
</html>
<?php

// Check if delete button active, start this  

// if(isset($_POST['delete'])){ 

// for($i=0;$i<count($_POST['checkbox']);$i++){ 

// $del_id = $_POST['checkbox'][$i]; 

// $sql = "UPDATE $tbl_name
//SET active_account= '0'
//WHERE id='$del_id'"; 

//$result = mysql_query($sql); 

//} 

// if successful redirect to delete_multiple.php 
//if($result){
//echo "<br>";
//echo "<h3> Record is successfully deleted. </h3>";
//echo "<br><br>";
// echo "<meta http-equiv=\"refresh\" content=\"0;URL=del.php\">";
//}
//}
// mysql_close();
?>

Open in new window

I copied your code, put in my own database info, and it works fine.  What errors are you getting?
No error - just no records displaying
Dang - I threw in error handling and got this - the WAMP I am running has a problem with mysqli - same problem as the first program

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\Bitnami\wampstack-5.4.39-0\apps\DCheckBox\htdocs\index.php on line 22
That warning comes from MySQL thru the PHP 'mysqli' driver and it is telling you that there is something wrong with your login.  It is not because of your version of WAMP.  I've been running the tests for your code on another machine where I have WAMP installed so I could use 'localhost' and I am not seeing that problem using my own login info.  I also have a copy on this machine that I can use to connect remotely to several other MySQL servers I have running here.
This info connects

//$host="localhost"; // Host name
//$username="root"; // Mysql username
//$password="######"; // Mysql password
//$db_name="maxibillions"; // Database name
//$tbl_name="employee_data"; // Table name

 I am using the same info when I use this and it does not connect
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '######');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'maxibillions');

// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

The only difference is mysqli as opposed to mysql - two different programs - both can connect with mysql and both cannot with mysqli using WAMP.

Both programs connect with IIS using
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '######');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'maxibillions');

// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

So it is not a wrong PW etc
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I changed the port setting in php.ini under the WAMP install since the default was 3306

Here is more detailed info

http://blog.ulf-wendel.de/2011/using-mysql-with-php-mysqli-connections-options-pooling/

Thanks