DB是一个与学生卡管理程序相结合的C ++。 输入您的信息以接收学生收到的第一个输入您的姓名和ID。问题是插入名称中存在错误。
直接从MS-DOS窗口插入(visual studio X) 韩文(韩语)很正常。
(尝试通过互联网查看的解决方法。)
当通过C ++插入时,Hangul(朝鲜语)不是。
hakbun int(50)not null主键, name char(100)not null
表的▲列,包括信息
▲查询状态
源代码
#include "stdio.h"
#include "winsock2.h"
#include "mysql.h"
#include "tchar.h"
#include <iostream>
#include <stdio.h>
using namespace std;
#pragma comment (lib, "libmysql.lib")
const char * host = "localhost";
const char * user = "root";
const char * pw = "1234";
const char * db = "point_db";
void DBconnect () {
MYSQL * connection = NULL, conn;
MYSQL_RES * sql_result;
MYSQL_ROW sql_row;
mysql_init (& conn);
connection = mysql_real_connect (& conn, host, user, pw, db, 3306, (char *) NULL, 0);
if (connection == NULL) {
printf ( "con error");
}
// Mysql_query (connection, "set session character_set_connection = utf-8;");
// Mysql_query (connection, "set session character_set_results = utf-8;");
// Mysql_query (connection, "set session character_set_client = utf-8;");
}
int _tmain (int argc, _TCHAR * argv []) {
MYSQL * connection = NULL;
MYSQL conn;
MYSQL_RES * sql_result;
MYSQL_ROW sql_row;
if (mysql_init (& conn) == NULL) {
printf ( "mysql_init () error!");
}
connection = mysql_real_connect (& conn, host, user, pw, db, 3306, (const char *) NULL, 0);
if (connection == NULL) {
printf ( "% d Error:% s,% d \ n", mysql_errno (& conn), mysql_error (& conn));
return 1;
}
else {
DBconnect ();
int query_stat;
char query [1024];
char num;
while (1) {
cout << "+ -------------------- +" << endl;
cout << "| ① create card |" << Endl;
cout << "+ -------------------- +" << endl;
cout << "Enter Number (Played: 0)>";
cin >> num;
switch (num) {
case '1':
int i, hakbun, student;
char name [100];
cout << "student number";
cin >> hakbun;
cout << "name";
cin >> name;
// Insert
sprintf_s (query, "insert into point (hakbun, name) values ( '% d', '% s')", hakbun, name);
query_stat = mysql_query (connection, query);
if (query_stat! = 0) {
printf ( "error:% s", mysql_error (& conn));
return 1;
}
else {
cout << "you have completed the creation card." << Endl;
}
default:
cout << "to end the program." << Endl;
exit (0);
}
}
}
}
my.ini文件详细信息
[mysqld]
basedir = C:/mysql-5.7.15-winx64
datadir = C:/mysql-5.7.15-winx64/data
port = 3306
# server_id = .....
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#add
character-set-client-handshake = FALSE
init_connect=”SET collation_connection = utf8_general_ci”
init_connect=”SET NAMES utf8″
character-set-server = utf8
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqldump]
default-character-set = utf8