hot fix Mysql

This commit is contained in:
October 2016-06-28 10:45:39 +08:00
parent 318f6cc378
commit 113a0f1d62

View File

@ -9,14 +9,18 @@ class Mysql{
private function connect( $is_master = true ){ private function connect( $is_master = true ){
if( $is_master ) $dbInfo = $this->master; if( $is_master ) $dbInfo = $this->master;
else $dbInfo = $this->slave; 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'] ); die('can\'t connect to mysql ' . $ $dbInfo['host'] );
}else{ }else{
// mysqli_query( "set names 'utf8'" , $db ); // mysqli_query( "set names 'utf8'" , $db );
mysqli_query( $db , "set names 'utf8'" ); //mysqli_query( $db , "set names 'utf8'" );
mysqli_query( $db , "set names 'utf8mb4'" );
} }
//echo 'connect to: '. $dbInfo['host'].'at db:'.$dbInfo['dbname'].'<br>'; //echo 'connect to: '. $dbInfo['host'].'at db:'.$dbInfo['dbname'].'<br>';
mysqli_select_db( $db , $dbInfo['dbname'] ); //mysqli_select_db( $db , $dbInfo['dbname'] );
return $db; return $db;
} }
@ -54,7 +58,7 @@ class Mysql{
//$GLOBALS['MYSQL_LAST_ERROR'] = mysqli_error($dblink); //$GLOBALS['MYSQL_LAST_ERROR'] = mysqli_error($dblink);
//$GLOBALS['MYSQL_LAST_ERRNO'] = mysqli_errno($dblink); //$GLOBALS['MYSQL_LAST_ERRNO'] = mysqli_errno($dblink);
if( 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 ) { public function runSql( $sql ) {
$ret = mysqli_query( $this->dbWrite() , $sql ); $ret = mysqli_query( $this->dbWrite() , $sql );
$this->saveError( $this->dbWrite() ); $this->saveError( $this->dbWrite );
return $ret; return $ret;
} }
public function getData( $sql , $key = NULL ){ public function getData( $sql , $key = NULL ){
@ -137,4 +141,4 @@ class Mysql{
public function error(){ public function error(){
return $GLOBALS['MYSQL_LAST_ERROR']; return $GLOBALS['MYSQL_LAST_ERROR'];
} }
} }