im Indian a novice and in php. I installed the wamp server2 that has the apacheserver,phpmyadmin and mysql but when I try to connect mysql through PHP code a error message - "Warning : Mysql_connect()[function.mysql.connect]; Access denied for user ' '@'localhost'(using password YES) in c:\wamp\www\school\temp.php on line 10." is comming so I cnat connect mysql. can someone help me.

Thanks
Susanta

Dani AI

Generated

The error shown in your first post indicates MySQL is rejecting an empty username: the message reports a user like ''@'localhost'. That usually means the PHP call that opens the connection is receiving an empty string for the username (wrong variable name, not set, or overwritten). 's Connector/J note is for Java and not relevant here; 's suggestion to test connectivity (telnet or CLI) is still a good step.

Quick checklist to find and fix the problem:

  • Confirm WAMP's MySQL service is running (WAMP tray icon).
  • Try logging in outside PHP: mysql -u root -p or use phpMyAdmin (bundled with WAMP) to verify a working account.
  • Verify the PHP variables you pass to the connection call are not empty. If you are using $_POST/$_GET values make sure they exist before calling the connect function.
  • Test TCP connectivity if needed: telnet 127.0.0.1 3306 (this only checks the port, not credentials).

Example fixes and safe setup (use mysqli or PDO rather than the old mysql extension):

$link = mysqli_connect('127.0.0.1', 'root', '');
if (! $link) {
    die('Connect error: ' . mysqli_connect_error());
}

If you need a dedicated web user, create one and grant minimal privileges from the MySQL console:

CREATE USER 'webuser'@'localhost' IDENTIFIED BY 'secret';
GRANT SELECT, INSERT, UPDATE ON school.* TO 'webuser'@'localhost';
FLUSH PRIVILEGES;

Notes and cautions: many WAMP installs use root with no password—if you supply a password when none exists you will also be denied. Check the MySQL account host (user@host) — user@localhost is different from user@127.0.0.1 and from user@%. Avoid running web apps as root; keep config files with credentials outside the web root.

See the PHP mysqli_connect docs for usage and the MySQL manual on account management for grant/authentication details: MySQL GRANT and account management.

Recommended Answers

All 2 Replies

hey even i m also new....
have u put mysql connector jar in classpath.
plz check

hey even i m also new....
have u put mysql connector jar in classpath.
plz check

I think the thread starter is talking about PHP and you r confusing it with the J-Connector.

So how are you connecting to the database, can we have some code to see what you tried ?
First hit the command "telnet <IP of system MySQL DB server installed on> 3306" to see if it connects.
If so are you able to login using the given user in mysql directly via the mysql command line client or via the mysql-gui tools with the given username and password?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.