testcrud.h
#pragma once
#include <mysql.h>
#include <iostream>
#include <vector>
#include <cstring> // 包含字符串操作相关的头文件
using namespace std;
typedef struct Test {
int id;
string name;
Test(){}
// 添加一个构造函数
Test(int id, string name){
this->id = id;
this->name = name;
}
}Test;
class testCrud{
testCrud();
~testCrud();
public:
//创建单例模式
static testCrud* getInstance() {
static testCrud instance; // 创建一个静态实例
return &instance; // 返回这个静态实例的地址
}
public:
bool test_insert(Test &test);
bool test_update(Test& test);
bool test_delete(Test& test);
vector<Test> test_select(string condition = "");
private:
MYSQL* con;
const char* host = "127.0.0.1";
const char* user = "root";
const char* password = "数据库密码";
const char* database_name = "数据库名";
const int port = 3306;
};