#include <iostream>
#include <mysql.h>
#include <string> #include <assert.h> int main()
{
MYSQL *ms_conn = mysql_init(NULL);
if (ms_conn == NULL)
{
std::cout << "Error: mysql_init failed." << std::endl;
return ;
}
std::cout << "Info: mysql_init success." << std::endl; // 参数CLIENT_MULTI_STATEMENTS 指定一次query 可以执行多条SQL
MYSQL *ms_temp = NULL;
ms_temp = mysql_real_connect(ms_conn, "localhost", "root", "123456sx",
"suyh", , NULL, CLIENT_MULTI_STATEMENTS);
if (ms_temp == NULL)
{
std::cout << "Error: mysql_real_connect() failed." << std::endl;
std::cout << mysql_error(ms_conn) << std::endl;
mysql_close(ms_conn), ms_conn = NULL;
return ;
}
std::cout << "Info: mysql_real_connect() succect." << std::endl; std::string str_sqls = "";
str_sqls += "SELECT id, account, sex, level, powers FROM player_data WHERE id = 100000";
str_sqls += ";";
str_sqls += "SELECT id, account, sex, level, powers FROM player_data WHERE id = 100001";
str_sqls += ";";
str_sqls += "SELECT id, account, sex, level, powers FROM player_data WHERE id = 100002"; int res = ;
res = mysql_real_query(ms_conn, str_sqls.c_str(), str_sqls.size());
if (res != )
{
std::cout << "Info: query failed, sql: " << str_sqls.c_str() << std::endl;
std::cout << mysql_error(ms_conn) << std::endl;
}
else
{
std::cout << "Info: query success." << std::endl;
std::cout << std::endl; // CLIENT_MULTI_STATEMENTS 指定该选项需要mysql_next_result() 函数来获取下一条结果集
// 如果结果集未取完,则不能进行query 操作。
do
{
MYSQL_RES *ms_res = mysql_store_result(ms_conn);
assert(ms_res != NULL); unsigned int field_num = mysql_num_fields(ms_res);
std::cout << "fileds number is " << field_num << std::endl; MYSQL_FIELD* field_info = mysql_fetch_field(ms_res);
assert(field_info != NULL); MYSQL_ROW row_data = NULL;
while ()
{
row_data = mysql_fetch_row(ms_res);
if (row_data == NULL)
break; unsigned long *field_lens = mysql_fetch_lengths(ms_res);
assert(field_lens != NULL);
for (int i = ; i < field_num; ++i)
{
if (field_info[i].type == MYSQL_TYPE_BLOB)
{
std::cout << "current filed type is BLOB." << std::endl;
continue;
} if (row_data[i] == NULL)
{
std::cout << "field_lens[" << i << "] = " << field_lens[i]
<< ", value is NULL." << std::endl;
}
else
{
std::cout << "field_lens[" << i << "] = " << field_lens[i]
<< ", value is " << row_data[i] << std::endl;
}
}
} mysql_free_result(ms_res), ms_res = NULL; std::cout << "#######################################" << std::endl;
} while (mysql_next_result(ms_conn) == );
} mysql_close(ms_conn), ms_conn = NULL;
return ;
}

MYSQL C API : CLIENT_MULTI_STATEMENTS 选项的更多相关文章

  1. c++使用mysql的api连接相关问题

    记录一下自己使用中的相关问题,方便有相同问题的同学解决. 关于在VS中的各种配置.看这里.只是须要注意一下,我如今用的mysql版本号是5.6的,已经没有[MySQL Server \lib\opt] ...

  2. MySQL C API概述

    以下列表总结了C API中可用的功能.有关更多详细信息,请参见 第27.8.7节“C API函数描述”中的说明. my_init():在线程安全程序中初始化全局变量和线程处理程序 mysql_affe ...

  3. MySql接口API函数综述

    C API函数概述 函数 描述 mysql_affected_rows() 返回上次UPDATE.DELETE或INSERT查询更改/删除/插入的行数. mysql_autocommit() 切换 a ...

  4. PHP数据库操作:从MySQL原生API到PDO

    本文将举详细例子向大家展示PHP是如何使用MySQL原生API.MySQLi面向过程.MySQLi面向对象.PDO操作MySQL数据库的. 为了后面的测试,先建立数据库表test.包含表名user,s ...

  5. mysql C API 字符串玩转备份调优

  6. The MySQL C API 编程实例

    在网上找了一些MYSQL C API编程的文章,看了后认为还是写的不够充分,依据自己经验写了这篇<The MySQL C API 编程实例>,希望对须要调用到MYSQL的C的API的朋友有 ...

  7. MySQL Backup mysqldump 常用选项与主要用法

    The mysqldump client utility performs logical backups, producing a set of SQL statements that can be ...

  8. MySQL原生API、MySQLi面向过程、MySQLi面向对象、PDO操作MySQL

    [转载]http://www.cnblogs.com/52fhy/p/5352304.html 本文将举详细例子向大家展示PHP是如何使用MySQL原生API.MySQLi面向过程.MySQLi面向对 ...

  9. MySQL C API(23)

    C API 提供了对 MySQL c/s 模型的底层访问.C API 代码在 mysqlclient 库中实现.可以从该库中引用到的变量及含义: 环境变量 含义 MYSQL_UNIX_PORT 本地连 ...

随机推荐

  1. 4、android之actionbar用法

    转: 上:http://blog.csdn.net/yuzhiboyi/article/details/32709833 下:http://blog.csdn.net/yuzhiboyi/articl ...

  2. Similarity-based Learning

    Similarity-based approaches to machine learning come from the idea that the best way to make a predi ...

  3. Allegro建立引脚封装概念名词梳理

    首先感谢于博士的60讲的Cadence教学视频,老师讲的还是很有耐心,很细致,谢谢! 目前还只是看到建立PCB封装这一块,正好手头上有个案子在做,边做边学的进度还是要好很多.以前的工作对原理图这一块的 ...

  4. Padding Oracle Attack的一些细节与实现

    Padding Oracle Attack还是颇具威力的,ASP.NET的Padding Oracle Attack被Pwnie评为2010年最佳服务端漏洞之一.还是看 Juliano Rizzo a ...

  5. get到的新技能

    1.重拾选择器 (一)类选择器与id选择器的区别 W3C标准这样规定的,在同一个页面内,不允许有相同名字的id对象出现,但是允许相同名字的class. 这样,一般网站分为头,体,脚部分,因为考虑到它们 ...

  6. Brief Tour of the Standard Library

    10.1. Operating System Interface The os module provides dozens of functions for interacting with the ...

  7. Unity3D DllNotFoundException/System.DllNotFoundException

    Unity System.DllNotFoundException Unity Fallback handler could not load library D:/91yGame/SparrowCD ...

  8. PHP数组操作汇总 php数组的使用技巧

    对于Web编程来说,最重要的就是存取和读写数据了.存储方式可能有很多种,可以是字符串.数组.文件的形式等.   数组,可以说是PHP的数据应用中较重要的一种方式.PHP的数组函数众多,下面是我学习的小 ...

  9. magento中如何实现产品图片放大效果

    Magento列表页用jQuery实现产品图片放大效果今天看到个网站,鼠标移到列表页的产品图片上,旁边会弹出一个大图,感觉不错,就自己在Magento里写了个.先看看效果 这个效果比较好实现,打开li ...

  10. Java常量字符串String理解

    Java常量字符串String理解 以前关于String的理解仅限于三点:1.String 是final类,不可继承2.String 类比较字符串相等时时不能用“ == ”,只能用  "eq ...