Modules/MTA-MySQL/mysql connect
Jump to navigation
Jump to search
Makes a connection to a MySQL server and returns a handler to it.
Syntax
handler mysql_connect ( string hostname, string username, string password, string database, [ int port=3306, string unix_socket=nil, string client_flags=""] )
Required arguments
- hostname: The hostname to connect to
- username: The database username
- password: The username password
- database: The starting database
Optional arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- port: The MySQL port
- unix_socket: When connecting in unix systems to a local database, the path for the unix socket (usually /var/run/mysqld/mysqld.sock)
- client_flags: The connection flags, with the format "flag1|flag2|flag3". The list of flags is:
- compress: Use compression protocol.
- found_rows: Return the number of found (matched) rows, not the number of changed rows.
- ignore_sigpipe: Prevents the client library from installing a SIGPIPE signal handler. This can be used to avoid conflicts with a handler that the application has already installed.
- ignore_space: Allow spaces after function names. Makes all functions names reserved words.
- interactive: Allow interactive_timeout seconds (instead of wait_timeout seconds) of inactivity before closing the connection. The client's session wait_timeout variable is set to the value of the session interactive_timeout variable.
- local_files: Enable LOAD DATA LOCAL handling.
- no_schema: Don't allow the db_name.tbl_name.col_name syntax. This is for ODBC. It causes the parser to generate an error if you use that syntax, which is useful for trapping bugs in some ODBC programs.
Returns
A valid MySQL handler if it was able to connect, or nil if it was unable.
Example
Example 1: This example makes a MySQL connection and checks if it was succesful.
handler = mysql_connect("localhost", "username", "password", "mta_users") -- Establish the connection if ( not handler ) then -- The connection failed outputDebugString("Unable to connect to the MySQL server") else mysql_close(handler) -- Close the connection end
See also
- mysql_connect
- mysql_close
- mysql_errno
- mysql_error
- mysql_ping
- mysql_select_db
- mysql_escape_string
- mysql_affected_rows
- mysql_change_user
- mysql_get_character_set_info
- mysql_get_client_info
- mysql_get_client_version
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_get_server_version
- mysql_hex_string
- mysql_info
- mysql_insert_id
- mysql_query
- mysql_unbuffered_query
- mysql_set_character_set
- mysql_stat
- mysql_warning_count