Using PHP with MySql

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
manishrathi
Forum Newbie
Posts: 6
Joined: Mon May 14, 2012 5:16 pm

Using PHP with MySql

Post by manishrathi »

I have installed wamp server(apache, mysql, php for windows). It installs phpMyAdmin. When I try to open phpMyAdmin, it gives an error
"Error

MySQL said: Documentation
#1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server."
I was never asked to setup username or password, then why am I getting such an error ?

Secondly, when I have to use a database with php, it asks for database user and database password. What is this user and password ? When I create a database, I dont provide a username or password for this database. So how can I get this ?

I already had MySql installed on my computer. So how does this affect new installation of MySql with wamp ? How do I know which MySql am I using ? New one or already existing one ?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Using PHP with MySql

Post by Christopher »

You need to create users in MySQL. These users have a username and password. You can also give the users access privileges. Or better is to create users with no privileges and then define the privileges that the user can have for each database they are allowed to access.
(#10850)
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: Using PHP with MySql

Post by egg82 »

wamp (xampp or lampp -> used to be called xampp -> used to be called wampp) is usually packaged with:

Apache
PHP
MySQL
FTP (I forgot which program)
SMTP (again, forgot)
Java Server? (no clue what, how, or why)

The default MySQL user/password for a standard xampp/lampp installation is root and null (as in nothing)
You do need these in order to connect to MySQL. If you don't have them, you can't connect.

MySQL returns errors to PHP through mysql_error();
run echo(mysql_error()); to see if you have any.

Also, if you really are using a version called "wampp" - your are using a very, very old version (2000-ish?) - get xampp (for windows) or lampp (for linux). I suppose you could also get xampp for mac or solaris. - install and enjoy. There should be no errors.
http://www.apachefriends.org/en/xampp.html <- xampp
TylerH4
Forum Newbie
Posts: 10
Joined: Sat May 26, 2012 8:45 pm

Re: Using PHP with MySql

Post by TylerH4 »

You can set your MySQL root password using http://localhost/security.
Post Reply