/** * Constructs a SQL clause about default character set and default collation for newly created databases and tables. * Example: Database::make_charset_clause('UTF-8', 'bulgarian') returns * DEFAULT CHARACTER SET `utf8` DEFAULT COLLATE `utf8_general_ci` * @param string $encoding (optional) The default database/table encoding (a system conventional id) to be used. * @param string $language (optional) Language (a system conventional id) used for choosing language sensitive collation (if it is possible). * @return string Returns the constructed SQL clause or empty string if $encoding is not correct or is not supported. * @author Ivan Tcholakov */ public static function make_charset_clause($encoding = null, $language = null) { if (empty($encoding)) { $encoding = api_get_system_encoding(); } if (empty($language)) { $language = api_get_interface_language(); } $charset_clause = ''; if (self::is_encoding_supported($encoding)) { $db_encoding = Database::to_db_encoding($encoding); $charset_clause .= " DEFAULT CHARACTER SET `" . $db_encoding . "`"; $db_collation = Database::to_db_collation($encoding, $language); if (!empty($db_collation)) { $charset_clause .= " DEFAULT COLLATE `" . $db_collation . "`"; } } return $charset_clause; }