c++ mysql sql 语句的编写_通过c++执行mysql的数据库语句

//通过mysql的数据库语句调用

1.string tt;

2.const char * t;

3.if(!mysql_real_query(&mysql,t,tt.length())==0)//成功返回0,此语句表示执行成功后的动作

a.创建表

char* pQuery="create table if not exists

DS_Building(ID VARCHAR(10),Name VARCHAR(10),PRIMARY KEY(ID))";

if(mysql_real_query(&mysql,pQuery,strlen(pQuery))==0)//执行语句,必须是const

char*类型

b.删除表

string del="drop table

DS_Building";//DS_Building是指表名

const char* dell=del.c_str();//c_str(),应#include

"string.h"

!mysql_real_query(&mysql,dell,del.length())

c.插入表

string insert1="insert into people

values('4','hou',56)";

const char* insertt=insert1.c_str();

mysql_real_query(&mysql,insertt,insert1.length())

d.更新表

int age=10;

string ageg;

stringstream ss;

ss<

p="">

ss>>ageg;

//类型转化,需要引入#include

string up="update people set Age="+ageg+" where

Id='1'";

const char* upp=up.c_str();

mysql_real_query(&mysql,upp,up.length());

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值