From c29bbf98ff5635f2c16230d5e62679c9fc58820f Mon Sep 17 00:00:00 2001
From: wy <18035202606@163.com>
Date: 星期二, 10 十二月 2024 15:36:50 +0800
Subject: [PATCH] wuyao
---
/dev/null | 0
GroupA_何敬治/Server/武尧/code/武尧_1210.txt | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git "a/GroupA_\344\275\225\346\225\254\346\262\273/Server/\346\255\246\345\260\247/code/\345\255\230\346\224\276\344\273\243\347\240\201.txt" "b/GroupA_\344\275\225\346\225\254\346\262\273/Server/\346\255\246\345\260\247/code/\345\255\230\346\224\276\344\273\243\347\240\201.txt"
deleted file mode 100644
index e69de29..0000000
--- "a/GroupA_\344\275\225\346\225\254\346\262\273/Server/\346\255\246\345\260\247/code/\345\255\230\346\224\276\344\273\243\347\240\201.txt"
+++ /dev/null
diff --git "a/GroupA_\344\275\225\346\225\254\346\262\273/Server/\346\255\246\345\260\247/code/\346\255\246\345\260\247_1210.txt" "b/GroupA_\344\275\225\346\225\254\346\262\273/Server/\346\255\246\345\260\247/code/\346\255\246\345\260\247_1210.txt"
new file mode 100644
index 0000000..d51d687
--- /dev/null
+++ "b/GroupA_\344\275\225\346\225\254\346\262\273/Server/\346\255\246\345\260\247/code/\346\255\246\345\260\247_1210.txt"
@@ -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;
+}
\ No newline at end of file
--
Gitblit v1.8.0