Login   Register  
PHP Classes
elePHPant
Icontem

File: pgsqlCascadeSelectAssoc.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Roberto Andrade Fonseca  >  Cascade Select Associative  >  pgsqlCascadeSelectAssoc.php  >  Download  
File: pgsqlCascadeSelectAssoc.php
Role: Example script
Content type: text/plain
Description: PostgreSQL and PEAR DB functions to retrieve the data as associative arrays
Class: Cascade Select Associative
Generate two dependent HTML form select inputs
Author: By
Last change:
Date: 9 years ago
Size: 1,984 bytes
 

Contents

Class file image Download
<?php
require_once 'DB.php';
//------------------------------------------------------------------------------------------
// Get mother data from PostgreSQL as an associative array for cascade select.
// motherTable:    The table with the mother data.
// motherPk:     The primary key of the table with the mother data.
// motherValue: The mother data value.
//------------------------------------------------------------------------------------------
function getMotherData($dbserver,$dbuser,$dbpass,$dbname,$motherTable$motherPk$motherValue){
        
$driver='pgsql';
        
$dsn=$driver.'://'.$dbuser.':'.$dbpass.'@'.$dbserver.'/'.$dbname;
        
$dbh=DB::connect($dsn);
        if(
DB::isError($dbh)) { die("Connection Error: ".$dbh->getMessage()); }
        
$query "SELECT $motherPk$motherValue FROM $motherTable;";
        
$data $dbh->getAssoc($query);
        return 
$data;
}

//------------------------------------------------------------------------------------------
// Get child data from PostgreSQL as an associative array for cascade select.
// childTable:    The table with the child data.
// childFk:     The foreing key of the table with the child data.
// childPk:     The primary key of the table with the child data.
// childValue:    The child data value.
//------------------------------------------------------------------------------------------
function getChildData($dbserver,$dbuser,$dbpass,$dbname,$childTable,$childFk,$childPk,$childValue)
{
        
$driver='pgsql';
        
$dsn=$driver.'://'.$dbuser.':'.$dbpass.'@'.$dbserver.'/'.$dbname;
        
$dbh=DB::connect($dsn);
        if(
DB::isError($dbh)) { die("Connection Error: ".$dbh->getMessage()); }
        
$query "select $childFk$childPk$childValue from $childTable;";
        
$result$dbh->query($query);
        
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
        
$data = array();
        while (
$row $result->fetchRow()) {
               
$data[$row[0]][$row[1]] = $row[2];
        }
        return 
$data;
}
?>