Changeset 42 for trunk/lib/DB.inc.php


Ignore:
Timestamp:
Dec 18, 2005 12:16:03 AM (18 years ago)
Author:
scdev
Message:

detabbed all files ;P

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/DB.inc.php

    r41 r42  
    99 * @version 1.0.1
    1010 */
    11  
     11
    1212class DB {
    1313
     
    3535        'db_die_on_failure' => false, // TRUE = script stops on db error.
    3636    );
    37    
     37
    3838    // Translate between HTML and MySQL character set names.
    3939    var $mysql_character_sets = array(
     
    4141        'iso-8859-1' => 'latin1',
    4242    );
    43    
     43
    4444    // Caches.
    4545    var $existing_tables;
    4646    var $table_columns;
    47    
     47
    4848    /**
    4949     * This method enforces the singleton pattern for this class.
     
    6363        return $instance;
    6464    }
    65    
     65
    6666    /**
    6767     * Constructor.
     
    119119        }
    120120    }
    121    
     121
    122122    /**
    123123     * Connect to database with credentials in params.
     
    132132            $this =& DB::getInstance();
    133133        }
    134        
     134
    135135        if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) {
    136136            App::logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
    137137            return false;
    138138        }
    139        
     139
    140140        // Connect to database. Always create a new link to the server.
    141         if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {   
     141        if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
    142142            // Select database
    143143            mysql_select_db($this->getParam('db_name'), $this->dbh);
    144144        }
    145        
     145
    146146        // Test for connection errors.
    147147        if (!$this->dbh || mysql_error($this->dbh)) {
     
    164164            }
    165165        }
    166        
     166
    167167        // DB connection success!
    168168        $this->_connected = true;
     
    173173        return true;
    174174    }
    175    
     175
    176176    /**
    177177     * Close db connection.
     
    186186            $this =& DB::getInstance();
    187187        }
    188        
    189         if (!$this->_connected) {
    190             return false;
    191         }
    192 
    193         mysql_close($this->dbh);       
    194     }
    195    
     188
     189        if (!$this->_connected) {
     190            return false;
     191        }
     192
     193        mysql_close($this->dbh);
     194    }
     195
    196196    /**
    197197     * Return the current database handler.
     
    207207            $this =& DB::getInstance();
    208208        }
    209        
     209
    210210        if (!$this->_connected) {
    211211            return false;
     
    214214        return $this->dbh;
    215215    }
    216    
     216
    217217    /**
    218218     * Returns connection status
     
    226226        return $this->_connected;
    227227    }
    228    
     228
    229229    /**
    230230     * A wrapper for mysql_query. Allows us to set the database link_identifier,
     
    238238    {
    239239        static $_query_count = 0;
    240        
    241         if (!isset($this) || !is_a($this, 'DB')) {
    242             $this =& DB::getInstance();
    243         }
    244        
     240
     241        if (!isset($this) || !is_a($this, 'DB')) {
     242            $this =& DB::getInstance();
     243        }
     244
    245245        if (!$this->_connected) {
    246246           return false;
     
    252252            echo "<!-- ----------------- Query $_query_count ---------------------\n$debugqry\n-->\n";
    253253        }
    254        
     254
    255255        // Execute!
    256256        $qid = mysql_query($query, $this->dbh);
    257    
     257
    258258        // Error checking.
    259259        if (!$qid || mysql_error($this->dbh)) {
     
    269269            }
    270270        }
    271    
     271
    272272        return $qid;
    273273    }
    274274
    275275    /**
    276      * Loads a list of tables in the current database into an array, and returns 
     276     * Loads a list of tables in the current database into an array, and returns
    277277     * true if the requested table is found. Use this function to enable/disable
    278      * funtionality based upon the current available db tables or to dynamically 
     278     * funtionality based upon the current available db tables or to dynamically
    279279     * create tables if missing.
    280280     *
     
    284284     */
    285285    function tableExists($table, $use_cached_results=true)
    286     {   
    287         if (!isset($this) || !is_a($this, 'DB')) {
    288             $this =& DB::getInstance();
    289         }
    290        
     286    {
     287        if (!isset($this) || !is_a($this, 'DB')) {
     288            $this =& DB::getInstance();
     289        }
     290
    291291        if (!$this->_connected) {
    292292            return false;
     
    307307        }
    308308    }
    309    
     309
    310310    /**
    311311     * Tests if the given array of columns exists in the specified table.
     
    318318     */
    319319    function columnExists($table, $columns, $strict=true, $use_cached_results=true)
    320     {   
    321         if (!isset($this) || !is_a($this, 'DB')) {
    322             $this =& DB::getInstance();
    323         }
    324        
     320    {
     321        if (!isset($this) || !is_a($this, 'DB')) {
     322            $this =& DB::getInstance();
     323        }
     324
    325325        if (!$this->_connected) {
    326326            return false;
     
    331331            return false;
    332332        }
    333        
     333
    334334        // For single-value columns.
    335335        if (!is_array($columns)) {
    336336            $columns = array($columns);
    337337        }
    338        
     338
    339339        if (!isset($this->table_columns[$table]) || !$use_cached_results) {
    340340            // Populate and cache array of current columns for this table.
     
    345345            }
    346346        }
    347    
     347
    348348        if ($strict) {
    349349            // Do an exact comparison of table schemas.
     
    359359        }
    360360    }
    361    
     361
    362362    /**
    363363     * Reset cached items.
     
    372372        $this->table_columns = null;
    373373    }
    374    
     374
    375375} // End.
    376376
Note: See TracChangeset for help on using the changeset viewer.