1. Download "libpq.dll" add inside "..\wamp64\bin\php\php7.3.12" folder
..\wamp64\bin\php\php7.3.12\libpq.dll
2. ..\wamp64\bin\php\php7.3.12\php.ini
Add and remove (;) semicolon
extension=php_pgsql.dll
extension=php_pdo_pgsql.dll
php.info
code Sample:
<?php
$host='localhost';
$db = 'todolist';
$username = 'postgres';
$password = '';
try{
$conn = new PDO("pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password");
$sth = $conn->prepare("SELECT * FROM staff");
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
echo "<pre>";
print_r($result);
if($conn){
echo "Connected to the <strong>$db</strong> database successfully!";
}
}catch (PDOException $e){
echo $e->getMessage();
}
Outpur:
Array
(
[id] => 1
[first_name] => Ram
[last_name] => Pukar
[comment] => Kumar
[status] => 0
[created_at] => 2018-01-01 00:00:00
[expire_date] => 2018-09-21
)
Connected to the todolist database successfully!


0 comments:
Post a Comment