mariadb set charset

From Onset Developer Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
mariadb set charset

Type: Function
Context: Server
Introduced: v1.0

NOTICE

This function is provided by the official MariaDB plugin.

Description

Sets the sqlserver charset to be used.

List of character sets: https://mariadb.com/kb/en/mysql_set_character_set/

Syntax

mariadb_set_charset(handle_id, charset_str)

Parameters

  • handle_id
    The connection handle.
  • charset_str
    The charset

Return Value

  • Returns true on success.

Example

Example taken from: https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/master/horizon/server/database.lua

sql = false

local SQL_HOST = "localhost"
local SQL_PORT = 3306
local SQL_USER = "user"
local SQL_PASS = "pass"
local SQL_DATA = "dbname"
local SQL_CHAR = "utf8mb4"
local SQL_LOGL = "debug"

-- Setup a MariaDB connection when the package/server starts
local function OnPackageStart()
	mariadb_log(SQL_LOGL)

	sql = mariadb_connect(SQL_HOST .. ':' .. SQL_PORT, SQL_USER, SQL_PASS, SQL_DATA)

	if (sql ~= false) then
		print("MariaDB: Connected to " .. SQL_HOST)
		mariadb_set_charset(sql, SQL_CHAR)
	else
		print("MariaDB: Connection failed to " .. SQL_HOST .. ", see mariadb_log file")

		-- Immediately stop the server if we cannot connect
		ServerExit()
	end

	CallEvent("database:connected")
end

See also