BFWSOA多种数据库的连接方式

BFWSOA多种数据库的连接方式

BFWSOA框架中Model层主要负责对数据库进行持久化,每个model层可以单独连接一个数据库或一张表,相互独立,支持分布式事务处理,读写分离设置

下面我们来演示一下常用的model层连接方式

1、mysql连接方式

$_config_arr['Db']['logicconfig'] = [
    "dbtype" => "DbMysql",
    "dbport" => 3306,
    "dbuser" => "root",
    "dbpwd" => "root",
    "dbname"=>"bfwdbname",
    "dbhost"=>"127.0.0.1"
];

2、sqllite;连接方式

$_config_arr['Db']['sqlconfig'] = [
    "dbtype" => "DbSqlite",
    "dbuser" => "root",
    "dbpwd" => "root",
    "dbname" => "bfwdbname",
    "dbhost" => DATA_DIR,
    "createsql" => "CREATE TABLE IF NOT EXISTS bfw_test (
            id INTEGER PRIMARY KEY,
            username TEXT,
            userpwd TEXT,
            token TEXT,
           regtime TEXT)"
];

3、mssql连接方式

$_config_arr['Db']['mssqlconfig'] = [
    "dbtype" => "DbMssql",
    "dbport" => 1433,
    "dbuser" => "root",
    "dbpwd" => "test",
    "dbname" => "dbname",
    "dbhost" => "127.0.0.1"
];

4、oracle连接方式

$_config_arr['Db']['oracleconfig'] = [
    "dbtype" => "DbOracle",
    "dbport" => 1521,
    "dbuser" => "test",
    "dbpwd" => "test",
    "dbname" => "dbname",
    "dbhost" => "localhost"
];

分布式事务处理方式

try {
			$_resarr = array ();
			$_res1 = Model_Member::getInstance ()->InsertData ( $_data, false, true );
			if ($_res1 ['err']) {
				Model_Member::getInstance ()->RollBack ();
				Model_Member::getInstance ()->ChangeBack ();
				return $_res1;
			}
			$_data_add ['id'] = $_res1 ['data'];
			$_resarr [] = Model_Member::getInstance ()->InsertDataAdd ( $_data_add, false, true );
			
			foreach ( $_resarr as $_res ) {
				if ($_res ['err']) {
					Model_Member::getInstance ()->RollBack ();
					Model_Member::getInstance ()->ChangeBack ();
					Model_Member_add::getInstance()->RollBack();
                                        Model_Member_add::getInstance()->ChangeBack();
					return $_res;
				}
			}
			Model_Member::getInstance ()->Commit ();
			Model_Member::getInstance ()->ChangeBack ();
			Model_Member_add::getInstance ()->Commit ();
			Model_Member_add::getInstance ()->ChangeBack ();
			
			return $_res1;
		} catch ( DbException $e ) {
			Model_Member::getInstance ()->RollBack ();
			Model_Member::getInstance ()->ChangeBack ();
			Model_Member_add::getInstance ()->RollBack ();
			Model_Member_add::getInstance ()->ChangeBack ();
			
			return Bfw::RetMsg ( true, $e->getMessage () );
}

{{collectdata}}

网友评论0

阿里云香港主机,免备案大优惠 打开浏览器开发html,体验云开发的乐趣bfweditor 打开浏览器即可开发php,bfwstudio
其他文章