栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++用mysql自带的头文件连接数据库

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++用mysql自带的头文件连接数据库

mysql.h文件在哪,怎么查找。自行百度

#include 
#include 
#include
#include
#include
using namespace std;
MYSQL *conn;
 MYSQL_RES *res;
 MYSQL_ROW row;
 
class people
{
public:
  char name[20];
  int pid;
  int type;
  char phone[30];
public:
  people(int a){};
  people(){
    setall();
  };
  ~people(){};
public:
  void setall();
 
};
 
void people::setall()
{
  cout<<"请输入该用户的编号"<>pid;
  cout<<"请输入该用户的名字"<>name;
  cout<<"请输入该用户的类型"<>type;
  cout<<"请输入该用户的联系方式"<>phone;
 
}
void save()
{
  char sql[1000];
  people a;
  sprintf(sql,"insert into student values(%d,'%s',%d,'%s')",a.pid,a.name,a.type,a.phone);
  if(mysql_query(conn, sql))
    {
      printf("添加失败: (%s)n",mysql_error(conn));
      return;
    }
    else
    {
      printf("添加成功!n");
      return;
    }
  return;
}
void update(){
  char sql[1000];
  people a(1);
  cout<<"请输入你要更改的用户的编号:";
  cin >> a.pid;
  cout<<"请输入你要此编号用户的姓名:";
  cin >> a.name;
  cout <<"请输入你要更改的用户的类型:";
  cin >> a.type;
  cout << "请输入你要更改的用户的电话:";
  cin >> a.phone;
  sprintf(sql,"update student set name = '%s',usetype=%d,phone='%s' where pid = %d",a.name,a.type,a.phone,a.pid);
    if(mysql_query(conn, sql))
      {
 printf("更改失败: (%s)n",mysql_error(conn));
 return;
      }
      else
      {
 printf("更改成功!n");
 return;
      }
    return;
}
void del()
{
  char sql[1000];
  int pid;
  cout<<"请输入你要删除的人的编号"<>pid;
  sprintf(sql,"delete from student where pid = %d",pid);
  if(mysql_query(conn, sql))
    {
      printf("删除 失败(%s)n",mysql_error(conn));
      return;
    }
    else
    {
      printf("删除成功!n");
      return;
    }
  return;
}
void menu()
{
  cout<<"1.用户录入"<>s;
    if(s==2){show();}
    if(s==1){save();}
    if(s==3){update();}
    if(s==4){del();}
    if(s==5){mysql_close(conn);return 0;}
    cout<<"按任意键继续.."<

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/64239.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号