链接MySQL数据库脚本文件_1

| 发表于 2020-7-20 00:08:28 | 显示全部楼层 |复制链接
  1. void OnStart()
  2. {
  3. string Host, User, Password, Database, Socket; // database credentials
  4. int Port,ClientFlag;
  5. int DB1,DB2,DB3; // database identifiers
  6. Print (MySqlVersion());
  7. string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
  8. string strDbConfig = terminal_data_path + "\\MQL4\\Scripts\\MyConnection.ini";
  9. Print("数据库配置文件路径:",strDbConfig);
  10. // reading database credentials from INI file
  11. Host = ReadIni(strDbConfig, "MYSQL", "Host");
  12. User = ReadIni(strDbConfig, "MYSQL", "User");
  13. Password = ReadIni(strDbConfig, "MYSQL", "Password");
  14. Database = ReadIni(strDbConfig, "MYSQL", "Database");
  15. Port     = StrToInteger(ReadIni(strDbConfig, "MYSQL", "Port"));
  16. Socket   = ReadIni(strDbConfig, "MYSQL", "Socket");
  17. ClientFlag = StrToInteger(ReadIni(strDbConfig, "MYSQL", "ClientFlag"));  
  18. Print ("Host: ",Host, ", User: ", User, ", Database: ",Database);
  19. // open database connection
  20. Print ("Connecting...");
  21. DB1 = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
  22. if (DB1 == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB1);}
  23. DB2 = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
  24. if (DB2 == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB2);}
  25. DB3 = MySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag);
  26. if (DB3 == -1) { Print ("Connection failed! Error: "+MySqlErrorDescription); } else { Print ("Connected! DBID#",DB3);}
  27. MySqlDisconnect(DB3);
  28. MySqlDisconnect(DB2);
  29. MySqlDisconnect(DB1);
  30. Print ("All connections closed. Script done!");
  31.    
  32. }
复制代码
最近访问 头像模式
举报

评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

精品外汇EA