michaela Posted June 21, 2012 Share Posted June 21, 2012 I keep getting this error: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'webuser'@'localhost' (using password: YES) in C:\xampp\htdocs\Untitled-2.php on line 10 when I run this script: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> I'm following the directions from bonus appendix. I went into the php.in file and checked my extentions. Everything matches up to the text and I'm not sure what I'm missing. Could someone help me? I would appreciate it a lot. Link to comment Share on other sites More sharing options...
margaux Posted June 21, 2012 Share Posted June 21, 2012 The error message is telling you that the password being used to connect to your database is incorrect. If you can't remember what originally set the password to be, you can change it via phpMyAdmin. 1 Link to comment Share on other sites More sharing options...
michaela Posted June 22, 2012 Author Share Posted June 22, 2012 Thank you for responding. I went into the config.inc file in the phpMyadmin files and I placed the password in this line: $cfg['Servers'][$i]['password'] = 'mypassword'; And I went into phpMyadmin and matched up the passwords. And I still get an error when I run: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> Link to comment Share on other sites More sharing options...
Edward Posted June 22, 2012 Share Posted June 22, 2012 DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); // Make the connection: $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); Here are some of my setting, i defined some constants for the values to be added to mysqli_connect function. What is your database name? Which page of the book are you working off? Link to comment Share on other sites More sharing options...
Edward Posted June 22, 2012 Share Posted June 22, 2012 I just check in config.inc in my phpmyadmin folder and found $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = true; I want to point out that even though i know my password is 'mypassword' that part in the config.inc file is blank, Link to comment Share on other sites More sharing options...
Larry Posted June 22, 2012 Share Posted June 22, 2012 The phpMyAdmin config file sets the information for phpMyAdmin to connect to MySQL. These values have to match those WITHIN MySQL itself, the same as any other PHP script. Link to comment Share on other sites More sharing options...
michaela Posted June 22, 2012 Author Share Posted June 22, 2012 Thank you guys for replying, I really appreciate it. I got lost at page A12 in the bonus apprendix. I created a new user in PhpMyadmin. Then I went to test and got a warning stated above. I think my database name is 'user.' I'm not sure what this is for: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); // Make the connection: $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); Sorry, I'm new at this. Could anyone explain? Link to comment Share on other sites More sharing options...
Edward Posted June 23, 2012 Share Posted June 23, 2012 DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); These are contants that were defined for the values for my mysql connection. You will have to find out what yours are first before you try to connect. Link to comment Share on other sites More sharing options...
unpredict2ble Posted June 23, 2012 Share Posted June 23, 2012 I keep getting this error: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'webuser'@'localhost' (using password: YES) in C:\xampp\htdocs\Untitled-2.php on line 10 when I run this script: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> I'm following the directions from bonus appendix. I went into the php.in file and checked my extentions. Everything matches up to the text and I'm not sure what I'm missing. Could someone help me? I would appreciate it a lot. Ok i originally had the same issue you are/were when i tried to create a root password first. Even after editing the necessary file to add my password, it still would not connect. What I recommend (cause it worked for me) is to uninstall your xampp. Remove the associated folder as well (c:/xampp). Reinstall the xammp and when you start Apache, MySQL, and Mercury. Then hit the 'ADMIN' button next to MySQL. Once inside PhpMyAdmin, go to 'Priviledges' tab. Create a new user, before you start trying to edit the root password. Once you verify the user account is created and gaining access, you can then change the root password if you so chose. If you're running it on your personal computer, with no one really using it other than you, does it really matter that you don't create a password? Anyways....the following code: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> You have to make sure when dealing with databases that the information reflects your database. Using the code posted above, you must have a user account of 'webuser', password must be 'BroWsing', and you must have a database name 'temp'. If not, this statement will not work on your setup. If need be, change the info to what fits your database. Thank you guys for replying, I really appreciate it. I got lost at page A12 in the bonus apprendix. I created a new user in PhpMyadmin. Then I went to test and got a warning stated above. I think my database name is 'user.' I'm not sure what this is for: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); // Make the connection: $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); Sorry, I'm new at this. Could anyone explain? Not sure if you fixed your previous problem, but it seems like you continued to move forward. Anyways, this code basically says, try to connect to database (DB_NAME), but if for whatever reason the connection fails, display an error. Visual errors are always nice to see vs a blank page. If the connection is successful, it gets assigned (=) to a variable named $dbc. I'll be continuously checking back to see if you're still having trouble. Goodluck! </Unpredict2ble> Link to comment Share on other sites More sharing options...
michaela Posted June 28, 2012 Author Share Posted June 28, 2012 I did it! I've been messing with it forever and I finally figured out (with everyone's help above) that these were wrong: <?php mysqli_connect ('localhost', 'webuser', 'BroWsIng', 'temp'); ?> I think when I started I created a user: webuser with password browsing but I had no database named temp. Is there a file where I can find this: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'mypassword'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'forum2'); I'm still a little unclear on where this comes from. So if I'm the only person on this computer I don' have to create a password? Could someone comment a little more on security. I read in the appendix that users shouldn't be granted all privileges. Anyone have a real world example for this? Shouldn't one user have all capabilities? Thanks 1 Link to comment Share on other sites More sharing options...
Larry Posted July 1, 2012 Share Posted July 1, 2012 If you're the only person on the computer and you're not worried about the security of the data, then you don't need to create a real MySQL user and password. But, in the real world, you'd create individual MySQL users, one or more for each site. Creating one user will all capabilities is a terrible security model. Create unique, individual users, each only having those powers they absolutely need. For example, I might create one MySQL user that the public side of the site will use, and that user can perform INSERT, SELECT, and UPDATE queries. I might then create another MySQL user that the admin side uses, and that user will also have DELETE privileges. Link to comment Share on other sites More sharing options...
Recommended Posts