iam using wamp server 2....i did not give any usernmae or password for connecting sqlserver
during the process of installation..now when i tried to connect my database through php script using mysql_connect("localhost","","") iam not getting connected..it displays access denied..
how can i get connected to my database..kindly provide help..

Dani AI

Generated

and pointed toward the usual WAMP default administrative account — that was a good first hint. An "access denied" from PHP usually means one of three things: the credentials are wrong, the MySQL server is not accepting connections from the host you used, or the account lacks privileges for the database you asked for. See the MySQL troubleshooting notes on "Access denied" for precise error reasons and matching fixes ().

Quick, practical checklist:

  • Verify MySQL is running (WAMP tray icon / Services) and that Apache/PHP are using the same PHP build as WAMP.
  • Open phpMyAdmin () to inspect users and reset the administrative password or create a new, limited user for your application. If phpMyAdmin fails to open, check the MySQL error log and restart the service.
  • Avoid using an administrative account for your application; create a dedicated DB user with only the needed privileges (see MySQL "CREATE USER" guidance (MySQL docs)).

For current PHP versions prefer modern APIs instead of the old mysql_* functions. Example using PDO:

try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=your_db;charset=utf8', 'app_user', 'password');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

This gives better error handling and security.

Recommended Answers

All 3 Replies

username is root by default.

mysql_connect("localhost","root","")

The default user for the database is root. Try giving ("localhost","root",""). That should work.

username is root by default.

mysql_connect("localhost","root","")

Grr! I got beaten by a few seconds again ! :P

commented: mote, LOL, jaldi bhaaga karr :P +4
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.