Modules/MySQL/MysqlOpen: Difference between revisions
Jump to navigation
Jump to search
m (MysqlOpen moved to Modules/MySQL/MysqlOpen) |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{ModuleFunction|MySQL}} | |||
This function opens a MySQL connection to a specific database on a database server. As soon as a connection is made (or timed out), the callback_function you passed as parameter is called and you can read/write to the database by using the [[mysqlQuery]] function. | This function opens a MySQL connection to a specific database on a database server. As soon as a connection is made (or timed out), the callback_function you passed as parameter is called and you can read/write to the database by using the [[mysqlQuery]] function. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool mysqlOpen ( string callback_function, string host, string user, string password, string database_name, int port )</syntaxhighlight> | <syntaxhighlight lang="lua">bool mysqlOpen ( mysql mysqlobj, string callback_function, string host, string user, string password, string database_name, int port )</syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''callback_function''' : The function that is called if the operation is done ( | *'''mysqlobj''' : mysql object (requires an established connection) | ||
*'''callback_function''' : The function that is called if the operation is done (see below) | |||
*'''host''' : The database server hostname or IP address to use | *'''host''' : The database server hostname or IP address to use | ||
*'''user''' : The database username to use | *'''user''' : The database username to use | ||
Line 17: | Line 18: | ||
===Callback Arguments=== | ===Callback Arguments=== | ||
Your callback function has to accept the following arguments: | Your callback function has to accept the following arguments: | ||
*'''bool''' result : Returns false on error, true on success | *'''bool''' result : Returns false on error, true on success | ||
Line 26: | Line 26: | ||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onMySQLOpen ( | function onMySQLOpen ( result ) | ||
if ( result ) then | if ( result ) then | ||
outputServerLog ( " | outputServerLog ( "MySQL connection established." ) | ||
else | else | ||
outputServerLog ( " | outputServerLog ( "MySQL connection failed." ) | ||
end | end | ||
end | end | ||
function mysqltest () | function mysqltest () | ||
mysqlOpen ( "onMySQLOpen", "localhost", "bastage", "bastage_pw", "test", 3306 ) | db = mysqlCreate () | ||
mysqlOpen ( db, "onMySQLOpen", "localhost", "bastage", "bastage_pw", "test", 3306 ) | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 20:45, 29 September 2009
This function is provided by the external module MySQL. You must install this module to use this function. | |
This function opens a MySQL connection to a specific database on a database server. As soon as a connection is made (or timed out), the callback_function you passed as parameter is called and you can read/write to the database by using the mysqlQuery function.
Syntax
bool mysqlOpen ( mysql mysqlobj, string callback_function, string host, string user, string password, string database_name, int port )
Required Arguments
- mysqlobj : mysql object (requires an established connection)
- callback_function : The function that is called if the operation is done (see below)
- host : The database server hostname or IP address to use
- user : The database username to use
- password : The database password to use
- database_name : The database name to use
- port : The database server port (MySQL default port is 3306)
Callback Arguments
Your callback function has to accept the following arguments:
- bool result : Returns false on error, true on success
Optional Arguments
None
Example
function onMySQLOpen ( result ) if ( result ) then outputServerLog ( "MySQL connection established." ) else outputServerLog ( "MySQL connection failed." ) end end function mysqltest () db = mysqlCreate () mysqlOpen ( db, "onMySQLOpen", "localhost", "bastage", "bastage_pw", "test", 3306 ) end