Skip to content

Instantly share code, notes, and snippets.

@dirkeinecke
Last active August 10, 2018 09:36
Show Gist options
  • Save dirkeinecke/af05998f21f7ef75fcf1bd3b5e9849a2 to your computer and use it in GitHub Desktop.
Save dirkeinecke/af05998f21f7ef75fcf1bd3b5e9849a2 to your computer and use it in GitHub Desktop.
<?php
if ($_SERVER['SERVER_NAME'] === 'REMOTE_HOST') {
// remote host data
define('DB_HOST', (string) 'REMOTE_DB_HOST');
define('DB_USER', (string) 'REMOTE_DB_USERNAME');
define('DB_PW', (string) 'REMOTE_DB_PASSWORD');
define('DB_DB', (string) 'REMOTE_DB');
} else {
// local host data
define('DB_HOST', (string) 'LOCAL_DB_HOST');
define('DB_USER', (string) 'LOCAL_DB_USERNAME');
define('DB_PW', (string) 'LOCAL_DB_PASSWORD');
define('DB_DB', (string) 'LOCAL_DB');
}
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PW, DB_DB);
if ($mysqli->connect_error) {
error_log(__FILE__ . ' ' . 'MySQL connect error: '.$mysqli->connect_error);
} else {
$mysqli->set_charset('utf8mb4');
$mysqli->query('SET NAMES utf8mb4');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment