Created
June 4, 2014 18:19
-
-
Save taichunmin/40ba1e8b06c25f853fc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
2012/09/03 taichunmin | |
2012/10/08 taichunmin add set_charset | |
*/ | |
switch($_SERVER['HTTP_HOST']) | |
{ | |
default: | |
$cfg['dbHost'] = 'localhost'; | |
$cfg['dbUser'] = 'username'; | |
$cfg['dbPass'] = 'dbpass'; | |
$cfg['dbDatabase'] = 'dbname'; | |
break; | |
} | |
function tai_mysqliConnect() | |
{ | |
// mysqli connect function | |
global $cfg,$mysqli; | |
$mysqli = new mysqli($cfg['dbHost'], $cfg['dbUser'], $cfg['dbPass'], $cfg['dbDatabase']); | |
if ($mysqli->connect_errno) | |
{ | |
die( "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ); | |
} | |
if (!$mysqli->set_charset("utf8")) | |
{ | |
printf("Error loading character set utf8: %s\n", $mysqli->error); | |
} | |
@$mysqli->query('SET CHARACTER_SET_CLIENT=utf8'); | |
@$mysqli->query('SET CHARACTER_SET_RESULTS=utf8'); | |
} | |
tai_mysqliConnect(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment