<NME> Db.php
<BEF> <?php
/*
Use for multiple-dbs:
1. config
	'db_my' => array()
2. php
	Db::use_db('my');
*/

/*
Db 类: 实现多个数据库的选择, 并以静态方法形式调用
iphp_DbInstance 类: 对应单个数据库, 同时实现读写分离
Mysql_i 类: 数据库连接(可建立只读连接), 所有对数据库的操作均通过此类
*/

// Db 类是为了方便使用 iphp_DbInstance, iphp_DbInstance 支持的所有实例方法,
// 均可作为本类的静态方法调用.
class Db{
	private static $app_config = array();
	static function is_readonly(){
		return self::$readonly;
	}

	static function instance(){
		if(self::$readonly){
			$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> add push_readonly/pop_readonly

<DFF> @@ -20,6 +20,22 @@ class Db{
 	static function is_readonly(){
 		return self::$readonly;
 	}
+	
+	private static $readonly_vars = array();
+	
+	static function push_readonly($yesno){
+		self::$readonly_vars[] = self::$readonly;
+		self::readonly($yesno);
+	}
+	
+	static function pop_readonly(){
+		if(!self::$readonly_vars){
+			throw new Exception("No vars to pop from readonly_vars!");
+		}
+		$yesno = array_pop(self::$readonly_vars);
+		self::readonly($yesno);
+		return $yesno;
+	}
 
 	static function instance(){
 		if(self::$readonly){

add push_readonly/pop_readonly