Modules/MySQL/MysqlOpen: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
==Description== | ==Description== | ||
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 | 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 is provided by the | This function is provided by the [[Module functions|ml_mysql]] module. | ||
==Syntax== | ==Syntax== | ||
Line 26: | Line 26: | ||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua"> | |||
function onMySQLOpen ( mysql, result ) | |||
if ( result ) then | |||
outputServerLog ( "CONNECTED" ) | |||
else | |||
outputServerLog ( "DIDNT WORK" ) | |||
end | |||
end | |||
function mysqltest () | |||
mysqlOpen ( "onMySQLOpen", "localhost", "bastage", "bastage_pw", "test", 3306 ) | |||
end | |||
</syntaxhighlight> |
Revision as of 01:22, 1 November 2006
Description
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 is provided by the ml_mysql module.
Syntax
bool mysqlOpen ( string callback_function, string host, string user, string password, string database_name, int port )
Required Arguments
- callback_function : The function that is called if the operation is done (please 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:
- mysql mysql : Returns the mysql object
- bool result : Returns false on error, true on success
Optional Arguments
None
Example
function onMySQLOpen ( mysql, result ) if ( result ) then outputServerLog ( "CONNECTED" ) else outputServerLog ( "DIDNT WORK" ) end end function mysqltest () mysqlOpen ( "onMySQLOpen", "localhost", "bastage", "bastage_pw", "test", 3306 ) end