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
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
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):
mysql -u root -p to verify credentials and that the server accepts connections. <?php phpinfo(); ?> and open it in the browser; search the output for mysqli or pdo_mysql to ensure a driver is loaded. 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).
Jump to Post— nav33n 472What error message ?
What error message ?
check your firewall, if it is on, off it then re-install the wamp.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.