db.class.php
查看本檔案說明文件.00001 <?php
00002
00009 include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/config/configfilestorage.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/database/adodb/adodb.inc.php" );
00012
00018 class Db extends Object
00019 {
00020
00021 function Db()
00022 {
00023 $this->Object();
00024 }
00025
00026 function &getDb()
00027 {
00028 static $db;
00029
00030 if( !isset( $db )) {
00031
00032 $fileConfig = new ConfigFileStorage();
00033
00034 $db = NewADOConnection('mysql');
00035
00036 $username = $fileConfig->getValue( "db_username" );
00037 $password = $fileConfig->getValue( "db_password" );
00038 $host = $fileConfig->getValue( "db_host" );
00039 $dbname = $fileConfig->getValue( "db_database" );
00040
00041 if( !$db->PConnect( $host, $username, $password, $dbname )) {
00042 throw( new Exception( "Fatal error: could not connect to the database!" ));
00043 die();
00044 }
00045
00046
00047
00048 $db->SetFetchMode( ADODB_FETCH_ASSOC );
00049 }
00050
00051 return $db;
00052 }
00053
00054 function &getDbCache()
00055 {
00056 static $dbcache;
00057
00058 if( !isset( $dbcache )) {
00059 $dbcache=Array();
00060 }
00061
00062 return $dbcache;
00063 }
00064
00071 function getPrefix()
00072 {
00073 $fileConfig = new ConfigFileStorage();
00074 $prefix = $fileConfig->getValue( "db_prefix" );
00075 return( $prefix );
00076 }
00077
00091 function qstr($string) {
00092
00093 if (get_magic_quotes_gpc()) {
00094 $string = stripslashes($string);
00095 }
00096
00097 $string = str_replace("'", "''", $string);
00098
00099 return $string;
00100 }
00101 }
00102 ?>