File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class Db{
2525 */
2626 private $ engine ;
2727 private $ params ;
28- private $ _engine_name ="pdo_mysql " ;
28+ private $ _engine_name ="mysql " ;
2929 private $ _allow_engines =array (
3030 "mysql " ,"mysqli " ,
3131 "pdo_mysql " ,"pdo_sqlite " ,"pdo_cubrid " ,
@@ -346,12 +346,12 @@ private function __query($sql, $retry=false){
346346 }
347347 //Connect
348348 if (!isset (Db::$ _globals [$ this ->_key ])){
349- if ($ this ->_engine_name == "mysql " || $ this ->_engine_name =="mysqli " ){
350- require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbMysqli.php " );
351- $ this ->engine = new \SlightPHP \DbMysqli ($ this ->params );
352- }else {
349+ if (strpos ($ this ->_engine_name ,"pdo_ " ) === 0 ){
353350 require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbPDO.php " );
354351 $ this ->engine = new \SlightPHP \DbPDO ($ this ->params );
352+ }else {
353+ require_once (SLIGHTPHP_PLUGINS_DIR ."/db/DbMysqli.php " );
354+ $ this ->engine = new \SlightPHP \DbMysqli ($ this ->params );
355355 }
356356 $ this ->engine ->init ($ this ->params );
357357 if ($ this ->engine ->connect ()===false ){
Original file line number Diff line number Diff line change @@ -63,24 +63,25 @@ public function connect(){
6363 $ tmp = explode ("_ " ,$ this ->_engine );
6464 $ driver =$ tmp [1 ];
6565 try {
66+ $ options = array (
67+ \PDO ::ATTR_PERSISTENT => $ this ->_persistent ,
68+ \PDO ::ATTR_STRINGIFY_FETCHES => false ,
69+ \PDO ::ATTR_EMULATE_PREPARES => false ,
70+ \PDO ::MYSQL_ATTR_USE_BUFFERED_QUERY => true ,
71+ );
72+ if (!empty ($ this ->_charset )){
73+ $ options [\PDO ::MYSQL_ATTR_INIT_COMMAND ]="SET CHARACTER SET {$ this ->_charset }, NAMES {$ this ->_charset }" ;
74+ }
6675 $ this ->_pdo = new \PDO (
6776 $ driver .":dbname= " .$ this ->_database .";host= " .$ this ->_host .";port= " .$ this ->_port ,
6877 $ this ->_user ,
6978 $ this ->_password ,
70- array (
71- \PDO ::ATTR_PERSISTENT => $ this ->_persistent ,
72- \PDO ::ATTR_STRINGIFY_FETCHES => false ,
73- \PDO ::ATTR_EMULATE_PREPARES => false ,
74- \PDO ::MYSQL_ATTR_USE_BUFFERED_QUERY => true ,
75- )
79+ $ options ,
7680 );
7781 }catch (\PDOException $ e ){
7882 trigger_error ("CONNECT DATABASE ERROR ( " .$ e ->getMessage ()." ) " ,E_USER_WARNING );
7983 return false ;
8084 }
81- if (!empty ($ this ->_charset )){
82- $ this ->_pdo ->exec ("SET NAMES " .$ this ->_charset );
83- }
8485 return true ;
8586 }
8687 public function query ($ sql ){
You can’t perform that action at this time.
0 commit comments