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 ){
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( $db , "set names 'utf8'" );
mysqli_query( $db , "set names 'utf8mb4'" );
}
//echo 'connect to: '. $dbInfo['host'].'at db:'.$dbInfo['dbname'].'<br>';
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 ){