1919 * @subpackage SDb
2020 */
2121namespace SlightPHP ;
22+ require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbPDO.php " );
23+ require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbMysqli.php " );
2224class Db{
2325 /**
2426 *
@@ -27,12 +29,12 @@ class Db{
2729 private $ params ;
2830 private $ _engine_name ="pdo_mysql " ;
2931 private $ _allow_engines =array (
30- "mysqli " ,
31- "pdo_mysql " ,"pdo_sqlite " ,"pdo_cubrid " ,
32- "pdo_dblib " ,"pdo_firebird " ,"pdo_ibm " ,
33- "pdo_informix " ,"pdo_sqlsrv " ,"pdo_oci " ,
34- "pdo_odbc " ,"pdo_pgsql " ,"pdo_4d "
35- );
32+ "mysqli " ,
33+ "pdo_mysql " ,"pdo_sqlite " ,"pdo_cubrid " ,
34+ "pdo_dblib " ,"pdo_firebird " ,"pdo_ibm " ,
35+ "pdo_informix " ,"pdo_sqlsrv " ,"pdo_oci " ,
36+ "pdo_odbc " ,"pdo_pgsql " ,"pdo_4d "
37+ );
3638 private $ _key ;
3739
3840 /**
@@ -53,9 +55,8 @@ class Db{
5355 */
5456 private $ error =array ('code ' =>0 ,'msg ' =>"" );
5557 /**
56- * @var array $_globals
58+ *
5759 */
58- static $ _globals ;
5960 function __construct ($ engineName ="mysql " ){
6061 $ this ->__setEngine ($ engineName );
6162 }
@@ -346,34 +347,24 @@ private function __query($sql, $retry=false){
346347 trigger_error ("{$ this ->_engine_name } ( $ sql ) " );
347348 }
348349 //Connect
349- if (!isset (Db::$ _globals [$ this ->_key ])){
350- if (extension_loaded ('pdo ' )){
351- require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbPDO.php " );
352- $ this ->engine = new \SlightPHP \DbPDO ($ this ->params );
353- }elseif (extension_loaded ('mysqli ' )){
354- require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbMysqli.php " );
355- $ this ->engine = new \SlightPHP \DbMysqli ($ this ->params );
356- }else {
357- trigger_error ("pdo and mysqli extension not exists " ,E_USER_ERROR );
358- unset(Db::$ _globals [$ this ->_key ]);
359- return false ;
360- }
361- $ this ->engine ->init ($ this ->params );
362- if ($ this ->engine ->connect ()===false ){
363- $ this ->error ['code ' ]=$ this ->engine ->errno ();
364- $ this ->error ['msg ' ]=$ this ->engine ->error ();
365- if (defined ("DEBUG " )){
366- trigger_error ("{$ this ->_engine_name } ( " .var_export ($ this ->error ,true ).") " );
367- }
368- unset(Db::$ _globals [$ this ->_key ]);
369- return false ;
370- }else {
371- Db::$ _globals [$ this ->_key ] = $ this ->engine ;
372- }
350+ if (extension_loaded ('pdo ' )){
351+ $ this ->engine = new \SlightPHP \DbPDO ($ this ->params );
352+ }elseif (extension_loaded ('mysqli ' )){
353+ $ this ->engine = new \SlightPHP \DbMysqli ($ this ->params );
373354 }else {
374- $ this ->engine = Db::$ _globals [$ this ->_key ];
355+ trigger_error ("pdo and mysqli extension not exists " ,E_USER_ERROR );
356+ return false ;
375357 }
376-
358+ $ this ->engine ->init ($ this ->params );
359+ if ($ this ->engine ->connect ()===false ){
360+ $ this ->error ['code ' ]=$ this ->engine ->errno ();
361+ $ this ->error ['msg ' ]=$ this ->engine ->error ();
362+ if (defined ("DEBUG " )){
363+ trigger_error ("{$ this ->_engine_name } ( " .var_export ($ this ->error ,true ).") " );
364+ }
365+ return false ;
366+ }
367+
377368 $ result = $ this ->engine ->query ($ sql );
378369
379370 if ($ result ){
@@ -389,7 +380,6 @@ private function __query($sql, $retry=false){
389380 }
390381 $ this ->error ['code ' ]=$ this ->engine ->errno ();
391382 $ this ->error ['msg ' ]=$ this ->engine ->error ();
392- unset(Db::$ _globals [$ this ->_key ]);
393383
394384 if ($ retry ===false && $ this ->engine ->connectionError ){
395385 $ this ->_reInit ();
0 commit comments