In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how to achieve a mysql general class in C++. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Without saying much, let's take a look at it.
Commonly used functions
Initialize the API library: mysql_library_init ()
Initialization data structure: mysql_init ()
Options before connecting to the database: mysql_options ()
Error message: mysql_error ()
Connection function: mysql_real_connect ()
Execute the SQL statement: mysql_query ()
Rollover query result: mysql_store_result ()
Close the connection: mysql_close ()
Dbctrl.h
# ifndef _ _ DBCTRL_H__#define _ DBCTRL_H__#include "winsock.h" # include "iostream.h" # include # include "mysql.h" # pragma comment (lib, "ws2_32.lib") # pragma comment (lib, "libmysql.lib") using namespace std;class DBctrl {private: MYSQL mydata / / MySQL object, a necessary data structure MYSQL_RES * result; / / it is recommended to use char* array to transfer this result to public: int row; / / the number of rows of query results int field / / number of columns of the query result int autoNum; / / the value of the last auto_increment int errorNum; / / error code const char* errorInfo; / / error prompt int affectedRow / / number of rows affected by the last query DBctrl (); / / Constructor void DBtest (int flag); void DBerror (); void DBconn (char* server, char* username, char* password, char* database,int port) Void DBquery (string queryStr); void DBquery (string queryStr, char* data); void DBclose ();}; # endif
Dbctrl.cpp
# include "dbctrl.h" / / Constructor initializes variables and data DBctrl::DBctrl () {mysql_library_init (zero null); mysql_init (& mydata); mysql_options (& mydata,MYSQL_SET_CHARSET_NAME, "gbk"); row=0; field=0; autoNum=0; errorNum=0; errorInfo= "ok"; affectedRow=0 } / / the test information is displayed at compile time, and void DBctrl::DBtest (int flag) {char* message; switch (flag) {case 1: message= "Database OK!"; break is available when you comment out the theme of this function. Case 2: message= "Database error!"; break; case 3: message= "Query OK!"; break; case 4: message= "Query error!"; break Case 5: message= "data overflew!"; break; default: message=NULL; break;} if (messageboxes null) cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.