a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 82|回复: 0

[红旗认证] 通过C++语言代码来操作MySQL数据库

[复制链接]
发表于 2012-8-4 12:16:06 | 显示全部楼层 |阅读模式
  代码:) b1 f! O) k$ }, ]6 Y& J1 z
  #include " l- _9 C$ l9 q: k+ L& |1 b$ R1 e( b* Z
  #include
, `7 g$ W$ o# N  #include "/usr/local/include/mysql/mysql.h" //安装的mysql的头文件所在的位置+ ^1 f5 Y2 L+ j) n7 y
  using namespace std;
4 u: V' g: s" v) g/ g5 @+ ~1 }7 `  string host="数据库地址";
1 W( |& u5 R! t- Y5 R( ?5 t2 X  string user="用户名";
) k3 M' q. d! s% T  string pwd="密码";
+ [( X0 G# P- G1 M! l6 L  string dbname="数据库";
8 e: S% B$ l& }3 f  string sql="查询语句";
1 d# s4 N. P; r, O, ^! q7 b  unsigned int port=3309;#端口号
) @. c$ s) H1 y  int status;8 I" _* Q$ S' n1 J
  int main(){
# H+ o2 t& ?% Q- c- c: \8 V& C  MYSQL *mysql;; F% d6 s2 z6 b: ^& W% U
  mysql=mysql_init(0);. t5 J: s, v) S
  MYSQL_RES *result;
; l( {( k  n$ I- l2 R  MYSQL_ROW row;
+ O2 `0 j: X3 {0 F" G  if(mysql_real_connect(mysql,host.c_str(),user.c_str(),pwd.c_str(),dbname.c_str(),port,NULL,CLIENT_FOUND_ROWS)==NULL){
3 l2 i( V4 L$ r4 }5 n7 Y  cout
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-6-3 04:54 , Processed in 0.160356 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表