I try to connect my PostgreSQL database to my website using PHP PDO, here my php code file(connnect.php):
<code><?php
$dsn = "pgsql:host=localhost;port=5432;dbname=family_tree";
$dbusername = "postgres";
$dbpassword = "12345678";
try {
$pdo = new PDO($dsn, $dbusername, $dbpassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo "Connection failed: " . $e->getMessage();
}
?>
</code>
<code><?php
$dsn = "pgsql:host=localhost;port=5432;dbname=family_tree";
$dbusername = "postgres";
$dbpassword = "12345678";
try {
$pdo = new PDO($dsn, $dbusername, $dbpassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo "Connection failed: " . $e->getMessage();
}
?>
</code>
<?php
$dsn = "pgsql:host=localhost;port=5432;dbname=family_tree";
$dbusername = "postgres";
$dbpassword = "12345678";
try {
$pdo = new PDO($dsn, $dbusername, $dbpassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo "Connection failed: " . $e->getMessage();
}
?>
I get a massage below:
Connection failed: could not find driver
So how can i solve the problem?
New contributor
伍嘉俊 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.