MSTLibrary3.1 database connection factory DBC
MST Library 3.1 database connection factory DBC
'Pdomysql', self: PDO_OCI => 'pdomainci', self: OCI8 => 'ci8',), $ _ importAdapters = array (), $ _ register = array (); protected static $ _ querySql = array (), $ _ lastHash = null; final static public function & connect ($ remote = null) {if ($ remote = null) $ remote = self: LOCAL; if (! Isset (self ::$ _ register [$ remote]) {$ config = MST_Core: getConfig (self ::$ _ dbConfigKey, $ remote ); if (empty ($ config) MST_Core: error (301, $ remote); if (empty ($ config ['adapter ']) |! Isset (self ::$ _ adapters [$ config ['adapter ']) MST_Core: error (302, $ remote); $ adapter = self :: $ _ adapters [$ config ['adapter ']; $ adapterClass = _ CLASS __. '_'. $ adapter; if (! Isset (self ::$ _ importAdapters [$ adapter]) {if (! MST_Core: import ("MST/DBC/{$ adapter}", MST_Core: P_LIB) |! Class_exists ($ adapterClass) MST_Core: error (302, "MST/DBC/$ adapter"); self ::$ _ importAdapters [$ adapter] = 1;} self :: $ _ register [$ remote] = new $ adapterClass ($ config);} return self: $ _ register [$ remote];} final static public function disconnect ($ remote = null) {if ($ remote = null) {foreach (self: $ _ register as $ conn) {if (! Empty ($ conn) $ conn-> disconnect () ;}} else {self: connect ($ remote)-> disconnect ();}} final static public function getConfig ($ key, $ remote = self: LOCAL) {if (empty (self: $ _ dbConfig [$ remote]) self :: $ _ dbConfig [$ remote] = MST_Core: getConfig (self ::$ _ dbConfigKey, $ remote); if (! Empty (self ::$ _ dbConfig [$ remote] [$ key]) return self ::$ _ dbConfig [$ remote] [$ key]; return null ;} final static public function addAdapter ($ key, $ val) {if (! Isset (self ::$ _ adapters [$ key]) self ::: _ adapters [$ key] = $ val;} final static public function getLastSqlHash () {return self:: $ _ lastHash;}/*** start Database transaction * @ param string $ remote connection instance */final static public function startTransaction ($ remote = self: LOCAL) {return self: connect ($ remote)-> startTransaction ();} /*** database transaction commit * @ param string $ remote connection instance */final static public function commit ($ remote = self: LOCAL) {return self :: connect ($ remote)-> commit ();} /*** database transaction rollBack * @ param string $ remote connection instance */final static public function rollBack ($ remote = self: LOCAL) {return self :: connect ($ remote)-> rollBack ();}/*** takes over * @ param unknown_type $ remote */final static public function handleDisconnect ($ remote = self:: LOCAL) {return self: connect ($ remote)-> takeOverDisconnect ();}}
2.Configuration File example
Array (), MST_Core: IN_DEV => array ('database' => array (MST_DBC: LOCAL => array ('adapter '=> MST_DBC: PDO_MYSQL, 'host' => '2017. 0.0.1 ', // database connection ip address 'user' => 'root', // database account 'password' => '', // database password 'dbname' => 'any _ db', 'prefix' => 'pf ',), 'iPhone' => array ('adapter '=> MST_DBC:: PDO_MYSQL, 'host' => '2017. 0.0.1 ', // database connection ip address 'user' => 'root', // database account 'password' => '', // database password 'dbname' => 'any _ db_iphone ', 'prefix' => false,),), MST_Mailer: FLAG => array (MST_Mailer :: LOCAL => array ('host' => 'localhost', 'port' => 25, 'debug' => 0, 'charset' => PROJECT_ENCODE, 'language' => PROJECT_LANG, MST_Mailer: IS_SMTP => true, MST_Mailer: SMTP_AUTH => false, MST_Mailer: FROM_MAIL => 'any @ host.com ', MST_Mailer :: FROM_NAME => 'anyone',),), MST_Core: IN_TEST => array ('database' => array (MST_DBC :: LOCAL => array ('adapter '=> MST_DBC: PDO_MYSQL, 'host' => '2017. 0.0.1 ', // database connection ip address 'user' => 'root', // database account 'password' => '', // database password 'dbname' => 'any _ db', 'prefix' => 'pf ',), 'iPhone' => array ('adapter '=> MST_DBC:: PDO_MYSQL, 'host' => '2017. 0.0.1 ', // database connection ip address 'user' => 'root', // database account 'password' => '', // database password 'dbname' => 'any _ db_iphone ', 'prefix' => false,),), MST_Mailer: FLAG => array (MST_Mailer :: LOCAL => array ('host' => 'localhost', 'port' => 25, 'debug' => 0, 'charset' => PROJECT_ENCODE, 'language' => PROJECT_LANG, MST_Mailer: IS_SMTP => true, MST_Mailer: SMTP_AUTH => false, MST_Mailer: FROM_MAIL => 'any @ host.com ', MST_Mailer :: FROM_NAME => 'anyone',),), MST_Core: IN_PRO => array ('database' => array (MST_DBC :: LOCAL => array ('adapter '=> MST_DBC: PDO_MYSQL, 'host' => '2017. 0.0.1 ', // database connection ip address 'user' => 'root', // database account 'password' => '', // database password 'dbname' => 'any _ db', 'prefix' => 'pf ',), 'iPhone' => array ('adapter '=> MST_DBC:: PDO_MYSQL, 'host' => '2017. 0.0.1 ', // database connection ip address 'user' => 'root', // database account 'password' => '', // database password 'dbname' => 'any _ db_iphone ', 'prefix' => false,),), MST_Mailer: FLAG => array (MST_Mailer :: LOCAL => array ('host' => 'localhost', 'port' => 25, 'debug' => 0, 'charset' => PROJECT_ENCODE, 'language' => PROJECT_LANG, MST_Mailer: IS_SMTP => true, MST_Mailer: SMTP_AUTH => false, MST_Mailer: FROM_MAIL => 'any @ host.com ', MST_Mailer :: FROM_NAME => 'anyone ',)),),);
The above is the content of the MST Library 3.1 database connection factory DBC. For more information, please follow the PHP Chinese network (www.php1.cn )!