PHP Classes

File: example.PostgreSQL80.php

Recommend this page to a friend!
  Classes of Richard Munroe   dm.DB   example.PostgreSQL80.php   Download  
File: example.PostgreSQL80.php
Role: Example script
Content type: text/plain
Description: Example for PostgreSQL 8.0
Class: dm.DB
Generic database access wrapper
Author: By
Last change:
Date: 17 years ago
Size: 2,517 bytes
 

Contents

Class file image Download
<?php

/**
 * @author Dick Munroe <munroe@csworks.com>
 * @copyright copyright @ 2006 by Dick Munroe, Cottage Software Works, Inc.
 * @license http://www.csworks.com/publications/ModifiedNetBSD.html
 * @version 1.0.0
 * @package dm.DB
 * @example ./example.php
 */

/*
 * This script assumes that the MySQL database created by DB.sql exists.
 */

//error_reporting(E_ALL & ~E_NOTICE);
//set_error_handler('errors') ;

include_once "class.factory.DB.php" ;
include_once
'../SDD/class.SDD.php' ;

/*
 * Put the value of your database login name into this variable.
 */

//$dblogin = "put your login name here" ;
$dblogin = "munroe" ;

/*
 * Put the value of your database login password into this variable.
 */

$dbpassword = "foreverpeace" ;

/*
 * Should you change the name of the database created by DB.sql, then
 * put the new name in the following variable.
 */

$dbdatabase = "DB" ;

$db = FactoryDB::factory($dblogin, $dbpassword, $dbdatabase, NULL, dmDB_PostgreSQL81);

$theTableNames = $db->showTables() ;
var_dump($theTableNames) ;
$theCreateTable = $db->showCreateTable($theTableNames[0]) ;
echo
$theCreateTable, "\n" ;

$db->queryConstant('SELECT "fullname" FROM "table" LIMIT 10');

include_once(
'../SDD/class.SDD.php') ;

/* loop through several rows of data */
while ($db->fetchRow()) {
        echo
$db->record["fullname"]."<br>\n";
}

/* this will echo "10" as the result count */
echo $db->resultCount()."<br>\n";

/* example of retrieving only one record and displaying it */
$db->queryConstant('SELECT "fullname" FROM "table" LIMIT 1');
$db->fetchRow();
echo
$db->record["fullname"]."<br>\n";

/* this will echo "1" as the result count */
echo $db->resultCount()."<br>\n";

/* if there were any records from the previous SELECT query, then "WOOHOO" will be printed */
if ($db->resultExist()) {
        echo
"WOOHOO";
}

/* optional clearing of result set before issuing a "SELECT" statement */
$db->clear();

/* Begin a transaction, INSERT a new record and get the last inserted id */
$db->beginTransaction();
$db->queryConstant('INSERT INTO "table" ("user", "password") values (\'am\', \'am2\') ;');
$db->commitTransaction();
echo
"<br>".$db->fetchLastInsertId('table_id_seq')."<br><br>\n";

/* diconnect and show errors */
$db->disconnect();
$db->showErrors();

function
errors($theCode, $theString, $theFile = NULL, $theLine = NULL)
{
    echo
$theFile . ':' . $theLine . ': ' . $theString . "\n" ;
}
?>