码蚁0817班级,AI项目,脸谱,双团队架构,赛马机制
wy
2024-12-10 c29bbf98ff5635f2c16230d5e62679c9fc58820f
wuyao
1个文件已添加
1个文件已删除
47 ■■■■■ 已修改文件
GroupA_何敬治/Server/武尧/code/存放代码.txt 补丁 | 查看 | 原始文档 | blame | 历史
GroupA_何敬治/Server/武尧/code/武尧_1210.txt 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
GroupA_ºÎ¾´ÖÎ/Server/ÎäÒ¢/code/´æ·Å´úÂë.txt
GroupA_ºÎ¾´ÖÎ/Server/ÎäÒ¢/code/ÎäÒ¢_1210.txt
New file
@@ -0,0 +1,47 @@
#include<mysql.h>
#include<iostream>
#include<string>
using namespace std;
const char* host = "127.0.0.1";
const char* user = "root";
const char* pw = "123456";
const char* database_name = "database_test";
const int port = 3306;
typedef struct Student
{
    int student_id;
    string student_name;
    string class_id;
}Student;
int main()
{
    MYSQL* con = mysql_init(NULL);
    //设置字符编码
    mysql_options(con, MYSQL_SET_CHARSET_NAME, "GBK");
    if (!mysql_real_connect(con, host, user, pw, database_name, port, NULL, 0))
    {
        fprintf(stderr, "Failed to connect to database : Error:%s\n", mysql_error(con));
        return -1;
    }
    Student stu{ 1111, "吴彦祖", "软件一班" };
    char sql[1024];
    //sprintf(sql, "insert into students (student_id,student_name,class_id) values(%d,'%s','%s')",
    //    stu.student_id, stu.student_name.c_str(), stu.class_id.c_str());
    sprintf_s(sql, sizeof(sql), "insert into students (student_id,student_name,class_id) values(%d,'%s','%s')",
        stu.student_id, stu.student_name.c_str(), stu.class_id.c_str());
    if (mysql_query(con, sql))
    {
        fprintf(stderr, "Failed to insert data : Error:%s\n", mysql_error(con));
        return -1;
    }
    mysql_close(con);
    system("pause");
    return 0;
}