/*
    这个文件可以只负责链接数据库，其他的都不管
    把数据库的句柄传给主程序
*/

/*
#include <iostream>
#include <mysql/mysql.h>

int main() {
    MYSQL *conn;
    conn = mysql_init(NULL);

    if (conn == NULL) {
        std::cerr << "MySQL init failed" << std::endl;
        return 1;
    }

    const char *server = "localhost";
    const char *user = "rtsw";
    const char *password = "123456";
    const char *database = "nginxdb";
    unsigned int port = 3306; // 使用云数据库提供的端口

    if (mysql_real_connect(conn, server, user, password, database, port, NULL, 0) == NULL) {
        std::cerr << "Connection error: " << mysql_error(conn) << std::endl;
        mysql_close(conn);
        return 1;
    }

    std::cout << "Successfully connected to the database" << std::endl;

    // ... 执行数据库操作 ...

    mysql_close(conn);
    return 0;
}
*/

#include "connector_database.h"

// DatabaseOperation函数定义
void DatabaseOperation() {
    MYSQL *conn = mysql_init(NULL);

    if (conn == NULL) {
        std::cerr << "MySQL init failed" << std::endl;
        return;
    }

    const char *server = "localhost";
    const char *user = "rtsw";
    const char *password = "123456";
    const char *database = "nginxdb";
    unsigned int port = 3306;

    if (mysql_real_connect(conn, server, user, password, database, port, NULL, 0) == NULL) {
        std::cerr << "Connection error: " << mysql_error(conn) << std::endl;
        mysql_close(conn);
        return;
    }

    std::cout << "Successfully connected to the database" << std::endl;

    // ... 执行数据库操作 ...

    mysql_close(conn);
}