#include <mysql.h>
#include <iostream>
#include <string>
using namespace std;
MYSQL *mysql;
int id; //职工号
int age;//年龄
int postcode;//邮编
int salary;//工资
string name;//姓名
string sex;//性别
string department;//部门
int w_id; //职工号
int w_age;//年龄
int w_postcode;//邮编
int w_salary;//工资
string w_name;//姓名
string w_sex;//性别
string w_department;//部门 int num;
void menu();
void add();
void dele();
void search();
void change();
void sal_sort();
void visitworker();
int main()
{
mysql = mysql_init(NULL);
if (NULL == mysql)
{
cout<<"error..."<<mysql_error(mysql)<< endl;
}
my_bool reconnect = true;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "gbk");
mysql_real_connect(mysql, "localhost", "root", "123456", "work", 3306, NULL, 0);
int num;
while (1)
{
menu();
cout << "请输入你要选择的功能选项(0-7):" << endl;
cin >> num;
switch(num)
{
case 1:
{
add();
break;
}
case 2:
{
change();
break;
}
case 3:
{
dele();
break;
}
case 4:
{
sal_sort();
break;
}
case 5:
{
search();
break;
}
case 6:
{
visitworker();
break;
}
case 0:
{
exit(1);
}
default:
{
cout << "输入值无效,请重新输入" << endl;
}
}
}
mysql_close(mysql);
return 0;
}
void add() //注册职工信息
{
cout <<"请输入职工的职工号 :"<< endl;
cin >> w_id;
cout <<"请输入职工的年龄 :"<< endl;
cin >> w_age;
cout <<"请输入职工的邮编 :"<< endl;
cin >> w_postcode;
cout <<"请输入职工的工资 :"<< endl;
cin >> w_salary;
cout <<"请输入职工的姓名 :"<< endl;
cin >> w_name;
cout <<"请输入职工的性别 :"<< endl;
cin >> w_sex;
cout <<"请输入职工的部门 :"<< endl;
cin >> w_department;
//int ret = mysql_query(mysql, "insert into values (id, age, postcode, salary, 'name', 'sex', 'department'");
char *insert_str = "insert into workers (id, age, postcode, salary, name, sex, department) values (%d, %d, %d, %d, '%s', '%s', '%s')";
char str[1024];
#include <iostream>
#include <string>
using namespace std;
MYSQL *mysql;
int id; //职工号
int age;//年龄
int postcode;//邮编
int salary;//工资
string name;//姓名
string sex;//性别
string department;//部门
int w_id; //职工号
int w_age;//年龄
int w_postcode;//邮编
int w_salary;//工资
string w_name;//姓名
string w_sex;//性别
string w_department;//部门 int num;
void menu();
void add();
void dele();
void search();
void change();
void sal_sort();
void visitworker();
int main()
{
mysql = mysql_init(NULL);
if (NULL == mysql)
{
cout<<"error..."<<mysql_error(mysql)<< endl;
}
my_bool reconnect = true;
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "gbk");
mysql_real_connect(mysql, "localhost", "root", "123456", "work", 3306, NULL, 0);
int num;
while (1)
{
menu();
cout << "请输入你要选择的功能选项(0-7):" << endl;
cin >> num;
switch(num)
{
case 1:
{
add();
break;
}
case 2:
{
change();
break;
}
case 3:
{
dele();
break;
}
case 4:
{
sal_sort();
break;
}
case 5:
{
search();
break;
}
case 6:
{
visitworker();
break;
}
case 0:
{
exit(1);
}
default:
{
cout << "输入值无效,请重新输入" << endl;
}
}
}
mysql_close(mysql);
return 0;
}
void add() //注册职工信息
{
cout <<"请输入职工的职工号 :"<< endl;
cin >> w_id;
cout <<"请输入职工的年龄 :"<< endl;
cin >> w_age;
cout <<"请输入职工的邮编 :"<< endl;
cin >> w_postcode;
cout <<"请输入职工的工资 :"<< endl;
cin >> w_salary;
cout <<"请输入职工的姓名 :"<< endl;
cin >> w_name;
cout <<"请输入职工的性别 :"<< endl;
cin >> w_sex;
cout <<"请输入职工的部门 :"<< endl;
cin >> w_department;
//int ret = mysql_query(mysql, "insert into values (id, age, postcode, salary, 'name', 'sex', 'department'");
char *insert_str = "insert into workers (id, age, postcode, salary, name, sex, department) values (%d, %d, %d, %d, '%s', '%s', '%s')";
char str[1024];