- void OnStart()
- {
- string Host, User, Password, Database, Socket; // database credentials
- int Port,ClientFlag;
- int DB1,DB2,DB3; // database identifiers
-
- Print (MySqlVersion());
-
-
- string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
- string strDbConfig = terminal_data_path + "\\MQL4\\Scripts\\MyConnection.ini";
- Print("数据库配置文件路径:",strDbConfig);
-
- // reading database credentials from INI file
- Host = ReadIni(strDbConfig, "MYSQL", "Host");
- User = ReadIni(strDbConfig, "MYSQL", "User");
- Password = ReadIni(strDbConfig, "MYSQL", "Password");
- Database = ReadIni(strDbConfig, "MYSQL", "Database");
- Port = StrToInteger(ReadIni(strDbConfig, "MYSQL", "Port"));
- Socket = ReadIni(strDbConfig, "MYSQL", "Socket");
- ClientFlag = StrToInteger(ReadIni(strDbConfig, "MYSQL", "ClientFlag"));
-
-
- Print ("Host: ",Host, ", User: ", User, ", Database: ",Database);
-
- // open database connection
- Print ("Connecting...");
-
- DB1 = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
-
- if (DB1 == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB1);}
-
- DB2 = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
-
- if (DB2 == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB2);}
-
-
- DB3 = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
-
- if (DB3 == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB3);}
-
- MySqlDisconnect(DB3);
- MySqlDisconnect(DB2);
- MySqlDisconnect(DB1);
- Print ("All connections closed. Script done!");
-
- }
复制代码
|