HtlMsql.cpp 908 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "pch.h"
  2. #include "HtlMsql.h"
  3. HtlMysql::HtlMysql()
  4. {
  5. p_sql = new MYSQL;
  6. mysql_init(p_sql);
  7. }
  8. HtlMysql::~HtlMysql()
  9. {
  10. mysql_close(p_sql);
  11. }
  12. HtlMysql* HtlMysql::GetInstance()
  13. {
  14. static HtlMysql htlmysql;
  15. return &htlmysql;
  16. }
  17. bool HtlMysql::Connect(DBINFO& Dbinfo)
  18. {
  19. if (mysql_real_connect(p_sql, Dbinfo.server_address, Dbinfo.user_name, Dbinfo.password, Dbinfo.database_name, Dbinfo.server_port, NULL, 0))
  20. {
  21. const char* aaa = "SET NAMES 'GB2312'";
  22. mysql_query(p_sql, aaa);
  23. p_sql->reconnect = true;
  24. return true;
  25. }
  26. else
  27. {
  28. return false;
  29. }
  30. }
  31. const char* HtlMysql::GetErrorInformation()
  32. {
  33. return mysql_error(p_sql);
  34. }
  35. bool HtlMysql::ExecutiveCommand(const char* SQLCommand)
  36. {
  37. if (mysql_ping(p_sql) == 0) {
  38. if(!mysql_query(p_sql, SQLCommand))
  39. {
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45. MYSQL_RES* HtlMysql::GetResultSet()
  46. {
  47. return p_res = mysql_store_result(p_sql);
  48. }