PHP Classes
Icontem

File: AccessBuilder.class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Christian Velin  >  DbCodeBuilder  >  AccessBuilder.class.php  
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
 

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;
    }
}


?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products