Skip to content

Instantly share code, notes, and snippets.

@taichunmin
Created June 4, 2014 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichunmin/40ba1e8b06c25f853fc8 to your computer and use it in GitHub Desktop.
Save taichunmin/40ba1e8b06c25f853fc8 to your computer and use it in GitHub Desktop.
<?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