<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marek+Jav%C5%AFrek</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marek+Jav%C5%AFrek"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Marek_Jav%C5%AFrek"/>
	<updated>2026-04-25T03:34:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/MTA-MySQL/mysql_connect&amp;diff=29836</id>
		<title>Modules/MTA-MySQL/mysql connect</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/MTA-MySQL/mysql_connect&amp;diff=29836"/>
		<updated>2012-04-01T16:14:56Z</updated>

		<summary type="html">&lt;p&gt;Marek Javůrek: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pageclass class=&amp;quot;#AA7592&amp;quot; subcaption=&amp;quot;MTA-MySQL Module&amp;quot;&amp;gt;&amp;lt;/pageclass&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
{{ModuleFunction|MTA-MySQL}}&lt;br /&gt;
Makes a connection to a MySQL server and returns a handler to it.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
MySQLConnection mysql_connect ( string hostname, string username, string password, string database, [ int port=3306, string unix_socket=nil, string client_flags=&amp;quot;&amp;quot;] )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Required arguments===&lt;br /&gt;
* '''hostname:''' The hostname to connect to&lt;br /&gt;
* '''username:''' The database username&lt;br /&gt;
* '''password:''' The username password&lt;br /&gt;
* '''database:''' The starting database&lt;br /&gt;
&lt;br /&gt;
===Optional arguments===&lt;br /&gt;
{{OptionalArg}}&lt;br /&gt;
* '''port''': The MySQL port&lt;br /&gt;
* '''unix_socket''': When connecting in unix systems to a local database, the path for the unix socket (usually /var/run/mysqld/mysqld.sock)&lt;br /&gt;
* '''client_flags''': The connection flags, with the format ''&amp;quot;flag1|flag2|flag3&amp;quot;''. The list of flags is:&lt;br /&gt;
** '''compress:''' Use compression protocol.&lt;br /&gt;
** '''found_rows:''' Return the number of found (matched) rows, not the number of changed rows.&lt;br /&gt;
** '''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.&lt;br /&gt;
** '''ignore_space:''' Allow spaces after function names. Makes all functions names reserved words.&lt;br /&gt;
** '''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.&lt;br /&gt;
** '''local_files:''' Enable LOAD DATA LOCAL handling.&lt;br /&gt;
** '''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.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
A valid MySQL handler if it was able to connect, or nil if it was unable.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
'''Example 1:''' This example makes a MySQL connection and checks if it was succesful.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
handler = mysql_connect(&amp;quot;localhost&amp;quot;, &amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;, &amp;quot;mta_users&amp;quot;) -- Establish the connection&lt;br /&gt;
if ( not handler ) then -- The connection failed&lt;br /&gt;
  outputDebugString(&amp;quot;Unable to connect to the MySQL server&amp;quot;)&lt;br /&gt;
else&lt;br /&gt;
  mysql_close(handler) -- Close the connection&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
'''Example 2:''' This example makes a MySQL connection and set charset&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local charset = &amp;quot;utf8&amp;quot;;&lt;br /&gt;
local handler = mysql_connect(&amp;quot;127.0.0.1&amp;quot;, &amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;, &amp;quot;database&amp;quot;, 3306, &amp;quot;/var/lib/libmysqlclient.so.15&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if (handler) then&lt;br /&gt;
	mysql_query(handler, &amp;quot;SET NAMES '&amp;quot;..charset..&amp;quot;'&amp;quot;)&lt;br /&gt;
	mysql_query(handler, &amp;quot;SET OPTION CHARACTER SET &amp;quot;..charset..&amp;quot;&amp;quot;)&lt;br /&gt;
	mysql_query(handler, &amp;quot;SET CHARACTER SET '&amp;quot;..charset..&amp;quot;'&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Modules/MTA-MySQL/Handler_functions}}&lt;/div&gt;</summary>
		<author><name>Marek Javůrek</name></author>
	</entry>
</feed>