mariadb set charset: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
{{Notice|This function is provided by the official [[MariaDB]] plugin.}} | {{Notice|This function is provided by the official [[MariaDB]] plugin.}} | ||
{{FuncDescription| | {{FuncDescription|Sets the sqlserver charset to be used. | ||
List of character sets: https://mariadb.com/kb/en/mysql_set_character_set/}} | |||
{{FuncSyntax|mariadb_set_charset(handle_id, charset_str)}} | {{FuncSyntax|mariadb_set_charset(handle_id, charset_str)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|handle_id| | {{FuncParam|handle_id|The connection handle.}} | ||
{{FuncParam|charset_str| | {{FuncParam|charset_str|The charset}} | ||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''true''' on success.}} | ||
== Example == | == Example == | ||
Example taken from: https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/master/horizon/server/database.lua | |||
<syntaxhighlight lang="Lua"> | <syntaxhighlight lang="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 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{MariaDBFunctions}} | {{MariaDBFunctions}} |
Latest revision as of 09:12, 2 September 2020
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