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 is comming so I cnat connect mysql. can someone help me.

Thanks
Susanta

Dani AI

Generated

As @ssusanta reported, WAMP Server2 is installed but PHP code cannot connect to MySQL. Common root causes are: the MySQL service is not running, the PHP MySQL extension is not enabled (or the PHP version no longer supports mysql*), wrong host/credentials, or a port/socket mismatch. 's point about the exact error message is critical — different messages point to different fixes (authentication vs server not listening vs missing extension). is correct that network rules matter for remote connections, but local PHP scripts usually fail for service/extension reasons.

Practical diagnostics (no external links required to follow these steps):

  • Confirm MySQL is running (WAMP tray icon or Windows Services) and port 3306 is listening.
  • From the server shell try mysql -u root -p to verify credentials and that the server accepts connections.
  • Create a short file with <?php phpinfo(); ?> and open it in the browser; search the output for mysqli or pdo_mysql to ensure a driver is loaded.
  • If the error is Call to undefined function mysql_connect(), enable the appropriate PHP extension or migrate away from deprecated mysql_* functions.

A modern, robust example uses PDO with exceptions and proper charset:

<?php
try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=your_db;charset=utf8mb4', 'root', '', [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]);
    echo 'Connected';
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
?>

For further, authoritative reference see the PHP PDO documentation (PDO connections) and WampServer official site (WampServer).

Recommended Answers

All 3 Replies

What error message ?

check your firewall, if it is on, off it then re-install the wamp.

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.