speedphp切换数据库处理

浏览594
  1. 修改数据配置信息

   $domain = array(
    "www.test3.com" => array( // 调试配置
        'debug' => 1,
        'mysql' => array(
            'MYSQL_HOST' => '127.0.0.1',
            'MYSQL_PORT' => '3306',
            'MYSQL_USER' => 'root',
            'MYSQL_DB' => 'ershou',
            'MYSQL_PASS' => 'root',
            'MYSQL_CHARSET' => 'utf8', 
        ),
    	'sendmysql'=>array(
    		'MYSQL_HOST' => '127.0.0.1',
    		'MYSQL_PORT' => '3306',
    		'MYSQL_USER' => 'root',
    		'MYSQL_DB'   => 'dianyun',
    		'MYSQL_PASS' => 'root',
    		'MYSQL_CHARSET' => 'utf8',
    	)
    ), 
);

2.使用方法

   /* 默认数据库 */  
		$result =get_model_other(array(), "cf_chat");
		print_r($result);  
		 
		/* 切换数据库 */
		M()->dbInstance($GLOBALS['sendmysql'], 'master', true);   
		$result =get_model_other(array(), "cf_chat");
		print_r($result); 
		
		/* 切换默认数据库  */
		M()->dbInstance($GLOBALS['mysql'], 'master', true);
		$result =get_model_other(array(), "cf_chat");
		print_r($result);




  • 暂无任何回答