PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Julien PACHET   pgSQL Abstract   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: How to use the class
Class: pgSQL Abstract
PostgreSQL access wrapper to simplify queries
Author: By
Last change:
Date: 19 years ago
Size: 1,019 bytes
 

Contents

Class file image Download
<?
 
require("class_pgsql.inc.php");
 
 
// opening connection
 
$pgsql=new pgsql("test","localhost","test","password_for_test","5432");
 
 
// creating table
 
$sql="CREATE TABLE table_test (
 id integer,
 field1 varchar,
 field2 varchar);"
;
 
$mysql->query($sql);
 
 
// inserting some datas
 
for ($i=0;$i<5;$i++) {
   
$pgsql->insert("table_test",array('id','field1','field2'),array("data ".$i,"other data ".$i));
   
 
// display content of table
 
print_r($pgsql->query("SELECT * FROM table_test ORDER BY field1"));
 
 
// an update to the table, for id=3
 
$pgsql->update("table_test",array('field1','field2'),array('aaa','bbb'),"id=3");
 
 
// display a field for id=4, if SELECT return no line, "none" return
 
echo $pgsql->select_value("SELECT field2 FROM table_test WHERE (id=4)","none");
 
 
// delete a line, for id=2
 
$pgsql->delete("table_test","id=2");
 
 
// display content of table
 
print_r($pgsql->query("SELECT * FROM table_test ORDER BY field1"));
 
?>