Changeset 468 for trunk/lib/DB.inc.php
- Timestamp:
- Feb 20, 2014 3:03:59 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
/branches/eli_branch merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/lib/DB.inc.php
r465 r468 32 32 class DB { 33 33 34 // A place to keep an object instance for the singleton pattern. 35 private static $instance = null; 36 34 37 // If $db->connect has successfully opened a db connection. 35 var$_connected = false;38 private $_connected = false; 36 39 37 40 // Database handle. 38 var$dbh;41 public $dbh; 39 42 40 43 // Count how many queries run during the whole instance. 41 var$_query_count = 0;44 private $_query_count = 0; 42 45 43 46 // Hash of DB parameters. 44 var$_params = array();47 private $_params = array(); 45 48 46 49 // Default parameters. 47 var$_param_defaults = array(50 private $_param_defaults = array( 48 51 49 52 // DB passwords should be set as apache environment variables in httpd.conf, readable only by root. … … 64 67 65 68 // Translate between HTML and MySQL character set names. 66 var$mysql_character_sets = array(69 public $mysql_character_sets = array( 67 70 'utf-8' => 'utf8', 68 71 'iso-8859-1' => 'latin1', … … 70 73 71 74 // Caches. 72 var$existing_tables;73 var$table_columns;75 private $existing_tables; 76 private $table_columns; 74 77 75 78 /** … … 80 83 * @static 81 84 */ 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; 91 92 } 92 93 … … 98 99 * @param array $params Array of parameters (key => val pairs). 99 100 */ 100 function setParam($params)101 public function setParam($params) 101 102 { 102 103 $app =& App::getInstance(); … … 117 118 * @return mixed Configured parameter value. 118 119 */ 119 function getParam($param)120 public function getParam($param) 120 121 { 121 122 $app =& App::getInstance(); … … 136 137 * @since 28 Aug 2005 14:02:49 137 138 */ 138 function connect()139 public function connect() 139 140 { 140 141 $app =& App::getInstance(); … … 146 147 147 148 // 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)) { 149 150 // Select database 150 151 mysql_select_db($this->getParam('db_name'), $this->dbh); … … 185 186 * @since 28 Aug 2005 14:32:01 186 187 */ 187 function close()188 public function close() 188 189 { 189 190 if (!$this->_connected) { … … 204 205 * @since 03 Jul 2013 14:50:23 205 206 */ 206 function reconnect()207 public function reconnect() 207 208 { 208 209 $this->close(); … … 221 222 * @since 15 Jan 2007 15:59:00 222 223 */ 223 function _fail()224 private function _fail() 224 225 { 225 226 if ($this->getParam('db_die_on_failure')) { … … 240 241 * @since 20 Aug 2005 13:50:36 241 242 */ 242 function getDBH()243 public function getDBH() 243 244 { 244 245 if (!$this->_connected) { … … 256 257 * @since 28 Aug 2005 14:58:09 257 258 */ 258 function isConnected()259 public function isConnected() 259 260 { 260 261 return (true === $this->_connected); … … 270 271 * @since 06 Mar 2006 16:41:32 271 272 */ 272 function escapeString($string)273 public function escapeString($string) 273 274 { 274 275 if (!$this->_connected) { … … 287 288 * @return resource Query identifier 288 289 */ 289 function query($query, $debug=false)290 public function query($query, $debug=false) 290 291 { 291 292 $app =& App::getInstance(); … … 336 337 * @return bool true if given $table exists. 337 338 */ 338 function tableExists($table, $use_cached_results=true)339 public function tableExists($table, $use_cached_results=true) 339 340 { 340 341 $app =& App::getInstance(); … … 368 369 * @return bool true if column(s) exist. 369 370 */ 370 function columnExists($table, $columns, $strict=true, $use_cached_results=true)371 public function columnExists($table, $columns, $strict=true, $use_cached_results=true) 371 372 { 372 373 if (!$this->_connected) { … … 416 417 * @since 15 Jun 2006 11:46:05 417 418 */ 418 function numQueries()419 public function numQueries() 419 420 { 420 421 return $this->_query_count; … … 428 429 * @since 28 Aug 2005 22:10:50 429 430 */ 430 function resetCache()431 public function resetCache() 431 432 { 432 433 $this->existing_tables = null; … … 436 437 } // End. 437 438 438 ?>
Note: See TracChangeset
for help on using the changeset viewer.