mariadb set charset
From Onset Developer Wiki
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
- OnQueryError
- mariadb_log
- mariadb_connect
- mariadb_connect_file
- mariadb_close
- mariadb_unprocessed_queries
- mariadb_async_query
- mariadb_query
- mariadb_await_query
- mariadb_query_file
- mariadb_await_query_file
- mariadb_errno
- mariadb_error
- mariadb_escape_string
- mariadb_prepare
- mariadb_set_charset
- mariadb_get_charset
- mariadb_stat
- mariadb_get_row_count
- mariadb_get_field_count
- mariadb_get_result_count
- mariadb_get_field_name
- mariadb_set_result
- mariadb_get_value_index
- mariadb_get_value_index_int
- mariadb_get_value_index_float
- mariadb_get_value_name
- mariadb_get_value_name_int
- mariadb_get_value_name_float
- mariadb_save_result
- mariadb_delete_result
- mariadb_set_active_result
- mariadb_unset_active_result
- mariadb_is_any_result_active
- mariadb_is_valid_result
- mariadb_get_affected_rows
- mariadb_get_warning_count
- mariadb_get_insert_id
- mariadb_get_query_exec_time
- mariadb_get_query_string
- mariadb_get_row
- mariadb_get_assoc