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


Ignore:
Timestamp:
Feb 20, 2014 3:03:59 AM (10 years ago)
Author:
anonymous
Message:

Completed integrating /branches/eli_branch into /trunk. Changes include:

  • Removed closing ?> from end of files
  • Upgrade old-style contructor methods to use construct() instead.
  • Class properties and methods defined as public, private, static or protected
  • Ensure code runs under E_ALL with only mysql_* deprecated warnings
  • Search for the '@' symbol anywhere it might be used to supress runtime errors, then replace with proper error recovery.
  • Run the php cli -l option to check files for syntax errors.
  • Bring tests up-to-date with latest version and methods of PHPUnit
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/lib/DB.inc.php

    r465 r468  
    3232class DB {
    3333
     34    // A place to keep an object instance for the singleton pattern.
     35    private static $instance = null;
     36
    3437    // If $db->connect has successfully opened a db connection.
    35     var $_connected = false;
     38    private $_connected = false;
    3639
    3740    // Database handle.
    38     var $dbh;
     41    public $dbh;
    3942
    4043    // Count how many queries run during the whole instance.
    41     var $_query_count = 0;
     44    private $_query_count = 0;
    4245
    4346    // Hash of DB parameters.
    44     var $_params = array();
     47    private $_params = array();
    4548
    4649    // Default parameters.
    47     var $_param_defaults = array(
     50    private $_param_defaults = array(
    4851
    4952        // DB passwords should be set as apache environment variables in httpd.conf, readable only by root.
     
    6467
    6568    // Translate between HTML and MySQL character set names.
    66     var $mysql_character_sets = array(
     69    public $mysql_character_sets = array(
    6770        'utf-8' => 'utf8',
    6871        'iso-8859-1' => 'latin1',
     
    7073
    7174    // Caches.
    72     var $existing_tables;
    73     var $table_columns;
     75    private $existing_tables;
     76    private $table_columns;
    7477
    7578    /**
     
    8083     * @static
    8184     */
    82     static function &getInstance()
    83     {
    84         static $instance = null;
    85 
    86         if ($instance === null) {
    87             $instance = new DB();
    88         }
    89 
    90         return $instance;
     85    public static function &getInstance()
     86    {
     87        if (self::$instance === null) {
     88            self::$instance = new self();
     89        }
     90
     91        return self::$instance;
    9192    }
    9293
     
    9899     * @param  array    $params     Array of parameters (key => val pairs).
    99100     */
    100     function setParam($params)
     101    public function setParam($params)
    101102    {
    102103        $app =& App::getInstance();
     
    117118     * @return mixed               Configured parameter value.
    118119     */
    119     function getParam($param)
     120    public function getParam($param)
    120121    {
    121122        $app =& App::getInstance();
     
    136137     * @since   28 Aug 2005 14:02:49
    137138     */
    138     function connect()
     139    public function connect()
    139140    {
    140141        $app =& App::getInstance();
     
    146147
    147148        // Connect to database. Always create a new link to the server.
    148         if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
     149        if ($this->dbh = @mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
    149150            // Select database
    150151            mysql_select_db($this->getParam('db_name'), $this->dbh);
     
    185186     * @since   28 Aug 2005 14:32:01
    186187     */
    187     function close()
     188    public function close()
    188189    {
    189190        if (!$this->_connected) {
     
    204205    * @since    03 Jul 2013 14:50:23
    205206    */
    206     function reconnect()
     207    public function reconnect()
    207208    {
    208209        $this->close();
     
    221222    * @since    15 Jan 2007 15:59:00
    222223    */
    223     function _fail()
     224    private function _fail()
    224225    {
    225226        if ($this->getParam('db_die_on_failure')) {
     
    240241     * @since   20 Aug 2005 13:50:36
    241242     */
    242     function getDBH()
     243    public function getDBH()
    243244    {
    244245        if (!$this->_connected) {
     
    256257     * @since   28 Aug 2005 14:58:09
    257258     */
    258     function isConnected()
     259    public function isConnected()
    259260    {
    260261        return (true === $this->_connected);
     
    270271     * @since   06 Mar 2006 16:41:32
    271272     */
    272     function escapeString($string)
     273    public function escapeString($string)
    273274    {
    274275        if (!$this->_connected) {
     
    287288     * @return resource         Query identifier
    288289     */
    289     function query($query, $debug=false)
     290    public function query($query, $debug=false)
    290291    {
    291292        $app =& App::getInstance();
     
    336337     * @return bool                         true if given $table exists.
    337338     */
    338     function tableExists($table, $use_cached_results=true)
     339    public function tableExists($table, $use_cached_results=true)
    339340    {
    340341        $app =& App::getInstance();
     
    368369     * @return bool                         true if column(s) exist.
    369370     */
    370     function columnExists($table, $columns, $strict=true, $use_cached_results=true)
     371    public function columnExists($table, $columns, $strict=true, $use_cached_results=true)
    371372    {
    372373        if (!$this->_connected) {
     
    416417    * @since    15 Jun 2006 11:46:05
    417418    */
    418     function numQueries()
     419    public function numQueries()
    419420    {
    420421        return $this->_query_count;
     
    428429     * @since   28 Aug 2005 22:10:50
    429430     */
    430     function resetCache()
     431    public function resetCache()
    431432    {
    432433        $this->existing_tables = null;
     
    436437} // End.
    437438
    438 ?>
Note: See TracChangeset for help on using the changeset viewer.