This class is made by unreal4u (Camilo Sperberg) and based on the Extended MySQLi class made by the same author. It haves exactly the same methods so that migrating from MySQL to PostGreSQL won't be so hard to do.
This package implements a PostGreSQL database access wrapper using the PDO extension.
There is class that manages PostGreSQL database access connections so only one connection is established during the same PHP script execution.
Another class implements other database access functions like executing queries with prepared queries, measuring the time the queries take to execute and the memory usage, retrieving query results into arrays, the number of result rows, last inserted record identifier and log executed queries to a valid XML log file or directly into your page.
If the query takes just too long, you can cache the query result into an XML file, and you can also handle errors.
This package has been extensivily tested with xDebug and Suhosin so that no errors are present.
include('config.php'); // Please see below for explanation include('extended_pgsql.class.php'); $dbLink = new extended_pgsql(); $id_user = 23; $username = 'unreal4u'; $aResult = $dbLink->query('SELECT id,username FROM users WHERE id = ? AND username = ?',$id_user,$username);
$aResult
haves the result of your query!foreach($aResult AS $a) { echo 'The id of the user named '.$a['username'].' is: '.$a['id'].'<br />'; }
unset($aResult);
define('CHARSET','UTF-8'); define('DB_SHOW_ERRORS',TRUE); // Show DB connection error to users? define('DB_LOG_XML',FALSE); // Log all database activity to XML? define('DB_URL_XML','/home/user/db-log.xml'); // Location of XML file, recommended place is outside the public html directory! define('DB_CACHE_LOCATION','cache/'); // Location of cache file(s), with trailing slash define('DB_CACHE_EXPIRE','60'); // DB cache file expiricy, in seconds define('PGSQL_HOST','localhost'); // your db's host define('PGSQL_PORT',5432); // your db's port define('PGSQL_USER','test'); // your db's username define('PGSQL_PASS','test'); // your db's password define('PGSQL_NAME','test'); // your db's database name define('PGSQL_FETCH_MODE',PDO::FETCH_ASSOC);