Beispiel #1
0
 public static bool Connect(string host, string username, string password, string db_name, uint port, string unix_socket = null, MySQL1.ClientFlags flags = (MySQL1.ClientFlags) 0uL)
 {
     if (!MySQL1.Initialized)
     {
         MySQL1.Initialize();
     }
     MySQL1.HostName     = host;
     MySQL1.HostPort     = port;
     MySQL1.Username     = username;
     MySQL1.Password     = password;
     MySQL1.Database     = db_name;
     MySQL1.UnixSocket   = unix_socket;
     MySQL1.ConnectFlags = (int)(flags | MySQL1.ClientFlags.CLIENT_MULTI_STATEMENTS);
     MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_OPT_CONNECT_TIMEOUT, Marshal.StringToCoTaskMemAnsi(MySQL1.ConnectTimeout.ToString()));
     MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_OPT_RECONNECT, Marshal.StringToCoTaskMemAnsi(MySQL1.Reconnect ? "1" : "0"));
     if (MySQL1.Charset.Equals("UTF8", StringComparison.OrdinalIgnoreCase))
     {
         MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_SET_CHARSET_NAME, Marshal.StringToCoTaskMemAnsi(MySQL1.Charset));
         MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_INIT_COMMAND, Marshal.StringToCoTaskMemAnsi("SET NAMES utf8"));
     }
     return(MySQL1.Connect());
 }