From 113a0f1d627465317f4a4fe98543134cc9dc7e14 Mon Sep 17 00:00:00 2001 From: October Date: Tue, 28 Jun 2016 10:45:39 +0800 Subject: [PATCH] hot fix Mysql --- engine/lib/Mysql.class.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/engine/lib/Mysql.class.php b/engine/lib/Mysql.class.php index c49bfa3..21fd3fe 100644 --- a/engine/lib/Mysql.class.php +++ b/engine/lib/Mysql.class.php @@ -9,14 +9,18 @@ class Mysql{ private function connect( $is_master = true ){ if( $is_master ) $dbInfo = $this->master; else $dbInfo = $this->slave; - if( !$db = mysqli_connect( $dbInfo['host'] , $dbInfo['user'] , $dbInfo['passwd'] ) ){ + if( !isset( $dbInfo['port'] ) || !$dbInfo['port'] ){ + $dbInfo['port'] = '3306'; + } + if( !$db = mysqli_connect( $dbInfo['host'] , $dbInfo['user'] , $dbInfo['passwd'] , $dbInfo['dbname'] , $dbInfo['port'] ) ){ die('can\'t connect to mysql ' . $ $dbInfo['host'] ); }else{ - // mysqli_query( "set names 'utf8'" , $db ); - mysqli_query( $db , "set names 'utf8'" ); + // mysqli_query( "set names 'utf8'" , $db ); + //mysqli_query( $db , "set names 'utf8'" ); + mysqli_query( $db , "set names 'utf8mb4'" ); } //echo 'connect to: '. $dbInfo['host'].'at db:'.$dbInfo['dbname'].'
'; - mysqli_select_db( $db , $dbInfo['dbname'] ); + //mysqli_select_db( $db , $dbInfo['dbname'] ); return $db; } @@ -54,7 +58,7 @@ class Mysql{ //$GLOBALS['MYSQL_LAST_ERROR'] = mysqli_error($dblink); //$GLOBALS['MYSQL_LAST_ERRNO'] = mysqli_errno($dblink); if( mysqli_errno($dblink) ){ - print_r( mysqli_error($dblink) ); + error_log( mysqli_error($dblink) ); } @@ -62,7 +66,7 @@ class Mysql{ public function runSql( $sql ) { $ret = mysqli_query( $this->dbWrite() , $sql ); - $this->saveError( $this->dbWrite() ); + $this->saveError( $this->dbWrite ); return $ret; } public function getData( $sql , $key = NULL ){ @@ -137,4 +141,4 @@ class Mysql{ public function error(){ return $GLOBALS['MYSQL_LAST_ERROR']; } -} \ No newline at end of file +}