Reputation: 11
l saw this problem many questions but l couldn't find the solution for myself. When l use WAMPSERVER it works with this way, but when l try hosting(free hosting) it gives this error. l am not very experienced so l am open to all answers. Thank you.
(Error: Connection failed: SQLSTATE[HY000] [2002] No such file or directory)
<?php
$servername = 'localhost';
$dbname = 'pro1';
$username = 'user1';
$password = 'barbar55';
$port = '3306';
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;port=$port", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
Upvotes: 0
Views: 630
Reputation: 11
I find out the problem. Aperently hosting service has a PANEL that l MUST use(silly me). It's my first time doing this so thanks for the answers.
Upvotes: 1
Reputation: 605
Try replace localhost
(socket connection) by IP address 127.0.0.1
(TCP connection)
Upvotes: 2