PHP Classes

File: AccessBuilder.class.php

Recommend this page to a friend!
  Classes of Christian Velin   DbCodeBuilder   AccessBuilder.class.php   Download  
File: AccessBuilder.class.php
Role: Class source
Content type: text/plain
Description: DB info collector class
Class: DbCodeBuilder
Generate code to access databases as data objects
Author: By
Last change: Changed license type
Date: 16 years ago
Size: 2,103 bytes
 

Contents

Class file image Download
<?php
/**
 * A class to retrieve info about database tables.
 *
 * @author Christian Velin, christian.velin@conjurer.org
 * @version 0.2
 * @since 0.1 Added phpdoc tags to each generated variable and method.
 * @package DbCodeBuilder
 *
 * Copyright (C) 2007 Christian Velin
 *
 * This program is free software; distributed under the artistic license.
 */
class AccessBuilder
{
   
/**
     * Variable to hold the db connection.
     *
     * @var unknown_type
     */
   
private $link;
   
   
/**
     * An array to store all the tables in the selected db.
     *
     * @var Array
     */
   
private $tables = array();
   
   
/**
     * A recursive array to hold all the column info for each of the tables.
     *
     * @var Array
     */
   
private $tableInfo = array();
   
   
   
    public function
__construct($host, $user, $pass, $db)
    {
       
$this -> link = mysql_connect($host, $user, $pass);
       
mysql_select_db($db);
    }
   
   
   
   
/**
     * A method to discover what tables are stored in the selected db and to store that information.
     *
     */
   
public function setTables()
    {
       
$result = mysql_query("SHOW tables", $this -> link);
        while(
$row = mysql_fetch_row($result))
        {
           
$this -> setColumnInfo($row[0]);
           
array_push($this -> tables, $row[0]);
        }
    }
   
   
   
   
/**
     * A method to get and store all information about the columns in each table.
     *
     * @param unknown_type $table
     */
   
private function setColumnInfo($table)
    {
       
$result = mysql_query("SHOW COLUMNS FROM " . $table);

        if (
mysql_num_rows($result) > 0)
        {
           
$info = array();
            while (
$row = mysql_fetch_assoc($result))
            {
               
array_push($info, $row);
            }
           
array_push($this -> tableInfo, $info);
        }
    }
   
   
   
   
/**
     * Method that returns the table information.
     *
     * @return Array an array with all available tables.
     */
   
public function getTables()
    {
        return
$this -> tables;
    }
   
   
   
   
   
/**
     * Method that returns the column information.
     *
     * @return unknown
     */
   
public function getColumnInfo()
    {
        return
$this -> tableInfo;
    }
}


?>