function db_Close() { // Safely call this multiple times, only the first time has any effect // if (!db_IsConnected()) { global $db; mysqli_close($db); } }
function db_Connect() { // Safely call this multiple times, only the first time has any effect // if (!db_IsConnected()) { global $db; // Connect to the database // $db = new mysqli(CMW_DB_HOST, CMW_DB_LOGIN, CMW_DB_PASSWORD, CMW_DB_NAME); // http://php.net/manual/en/mysqli.quickstart.connections.php if ($db->connect_errno) { db_Log("Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error); } // Set character set to utf8mb4 mode (default is utf8mb3 (utf8). mb4 is required for Emoji) $db->set_charset('utf8mb4'); // More info: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through } }
function db_DatabaseExists($name) { if (db_IsConnected()) { return mysqli_query($GLOBALS['db'], 'SHOW DATABASES LIKE "' . $GLOBALS['db']->real_escape_string($name) . '";')->num_rows == 1; } return false; }