<NME> Db.php
<BEF> <?php
include(dirname(__FILE__) . '/Mysql.php');

class Db{
	private static $config = array();

	function __construct(){
		throw new Exception("Static class");
/*
Db 类: 实现多个数据库的选择, 并以静态方法形式调用
	static function init($config=array()){
		self::$config = $config;
	}

	static function instance(){
		static $db = null;
		if($db === null){
			$db = new Mysql(self::$config);
	static function instance(){
		$dbname = self::$current_dbname;
		$key = $dbname? "db_{$dbname}" : 'db';
		if(!isset(self::$app_config[$key])){
			_throw("no config for db: $dbname");
		}
		if(!isset(self::$instances[$dbname])){
			$instance = new iphp_DbInstance(self::$app_config[$key]);
			self::$instances[$dbname] = $instance;
		}
		return self::$instances[$dbname];
	}

	static function __callStatic($cmd, $params=array()){
		return call_user_func_array(array(self::instance(), $cmd), $params);
	}
	
	static function build_in_string($val){
		if(is_string($val)){
			$val = explode(',', $val);
		}else if(is_array($val)){
			//
		}else{
			$val = array($val);
		}
		$tmp = array();
		foreach($val as $p){
			$p = trim($p);
			if(!strlen($p)){
				continue;
			}
			$p = self::escape($p);
			$tmp[$p] = $p;
		}
		return "'" . join("', '", $tmp) . "'";
	}
}

<MSG> update

<DFF> @@ -1,8 +1,9 @@
 <?php
-include(dirname(__FILE__) . '/Mysql.php');
+require_once(dirname(__FILE__) . '/Mysql.php');
 
 class Db{
 	private static $config = array();
+	private static $readonly = false;
 
 	function __construct(){
 		throw new Exception("Static class");
@@ -11,8 +12,23 @@ class Db{
 	static function init($config=array()){
 		self::$config = $config;
 	}
+	
+	static function readonly($yesno=true){
+		self::$readonly = $yesno;
+	}
 
 	static function instance(){
+		if(self::$readonly){
+			static $readonly_db = null;
+			if($readonly_db === null){
+				if(isset(self::$config['readonly_db'])){
+					$readonly_db = new Mysql(self::$config['readonly_db']);
+				}
+			}			
+			if($readonly_db){
+				return $readonly_db;
+			}
+		}
 		static $db = null;
 		if($db === null){
 			$db = new Mysql(self::$config);

update