Jump to content
Larry Ullman's Book Forums

Testing Php And Mysql - Mysqli_Test.Php - Help


Recommended Posts

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. :D

Link to comment
Share on other sites

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

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

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

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

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

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. :D

 

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

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 ^_^

  • Upvote 1
Link to comment
Share on other sites

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

 Share

×
×
  • Create New...