PDO PgSQL


 

PDO PgSQL

In this tutorial we will study about PDO PgSQL in PHP, how to access PgSQL using PDO, etc. Examples will make this clearer.

In this tutorial we will study about PDO PgSQL in PHP, how to access PgSQL using PDO, etc. Examples will make this clearer.

PHP-PDO Connectivity with PostgreSQL:

We can connect with PgSQL database using conventional way pg_connect. But in this tutorial we will connect with PDO. Since it is based on object oriented method, we need to instantiate an object of the class PDO. The database connection is handled internally by PDO's constructor (__construct()).

Example:

<?php

try {

$db = new PDO("pgsql:dbname=db;host=localhost", "postgres", "1234" );

echo "PDO connection object created";

}

catch(PDOException $e)

{

echo $e->getMessage();

}

?>

Output:

PDO connection object created

 

 

Ads