Location: PHPKode > scripts > Table Data Management > table-data-management/TableColumn.class.php
<?php
/**
 * The TableColumn object is used by the TableDataManagement object.
 * Every column in a certain table will have a initialized TableColumn.
 *
 * The TableColumn object is used so that we keep knowledge about the type
 * of the column and that way can specify what to do when retrieving or storing
 * a specific column (as to returning an integer, when the column is an integer)
 *
 * @package	database
 * @see		TableDataManagement
 * @version	1.0
 * @author	S.Radovanovic
 *
 */
class TableColumn {
	
	/** @var _name columnname **/
    var $_name;
    /** @var _value columnvalue **/
    var $_value;    
    /** @var _type columntype **/
    var $_type;
    /** @var _label columnlabel (if present) **/
    var $_label;

       
    /** 
     * On initialization we at least must know the name and the type of the column
     * @param String $name Name of the column
     * @param String $type Columntype
     * @param unknown_type $value
     */
    function TableColumn($name, $type, $value = null) {
        $this->_name = $name;
        $this->_type = $type;
        if(isset($value)) $this->setValue($value);        
    }
    
    
    /**
     * Set the value of the intialized column.
     *
     * @param unknown_type $value
     */
    function setValue($value) {
        $this->_value = $value;
    }
    
    /**
     * Return the appropriate database value.
     * It casts the value into the the type specified on initialization 
     *
     * @return value
     */
    function getDBValue() {            
        if( stristr($this->_type, "int") ) {
            $value = intval($this->_value);
        } elseif (  
                stristr($this->_type, "char") || 
                stristr($this->_type, "date") || stristr($this->_type, "time") ||
                stristr($this->_type, "text") || stristr($this->_type, "blob") ||
                stristr($this->_type, "set") || stristr($this->_type, "enum")
                ) {
            $value = '"'.strval(mysql_escape_string($this->_value)).'"';
        } elseif ( 
                stristr($this->_type, "float") || stristr($this->_type, "double") || stristr($this->_type, "real") ) {
            $value = doubleval($this->_value);
        } elseif ( stristr($this->_type, "decimal") || stristr($this->_type, "numeric") ) {
            $value = doubleval($this->_value);
        }
        
        return $value;
    }
    
    /**
     * Retrieve the set value (disregarding the type of the column)
     *
     * @return unknown_type
     */
    function getValue() {
        return $this->_value;
    }
    
    /**
     * Retrieve the name of the initialized column
     *
     * @return String _name
     */
    function getName() {
        return $this->_name;
    }
    
    /**
     * Set the label for the specified column
     *
     * @param String $label
     */
    function setLabel($label) {
    	$this->_label = $label;
    }
    
    /**
     * Retrieve the label 
     * 
     * @return String label
     */
    function getLabel() {
    	return $this->_label;
    }
    
}
?>
Return current item: Table Data Management