int rc;
int db_connection;
char *server = "192.168.139.207"; // 数据库的ip地址
char *user = "cloud"; // 数据库访问用户名
char *password = "cloudtest"; // 密码
char *database = "sklCloud"; // 数据库名称
int port = 3306; // 访问端口
int unix_socket = NULL;
int flags = 0;
char** result_row;
int query_result;
char szSql[256];

int MySqlInit()
{
rc = lr_load_dll("libmysql.dll");
db_connection = mysql_init(NULL);

if (db_connection == NULL)
{
lr_error_message("Insufficient memory");
lr_abort();
}

if(rc!=0)
{
lr_error_message("Load MySql.dll Error!");
lr_abort();
}

rc = mysql_real_connect(db_connection,server, user, password, database, port, unix_socket, flags);
if(rc == NULL)
{
lr_error_message("connect mysql error! %s",mysql_error(db_connection));
mysql_close(db_connection);
lr_abort();
}
return rc;
}

int MySqlUnit()
{
// 释放MySQL资源
mysql_close(db_connection);
return 0;
}

int InsertValue(char* query)
{
rc = mysql_query(db_connection,query);
if (rc != 0)
{
lr_error_message("%s", mysql_error(db_connection));
}

query = NULL;
return rc;
}

int MySqlQuery(char* szSql)
{
rc = mysql_query(db_connection,szSql);

if(rc != 0)
{
lr_error_message("%s",lr_eval_string("?"));
lr_error_message("%s", mysql_error(db_connection));
szSql = NULL;
return -1;
}

query_result = mysql_use_result(db_connection);
if (query_result == NULL)
{
lr_error_message("%s", mysql_error(db_connection));
mysql_free_result(query_result);
szSql = NULL;
return -2;
}

result_row = (char **)mysql_fetch_row(query_result);
if (result_row == NULL)
{
lr_error_message("Did not expect the result set to be empty");
mysql_free_result(query_result);
szSql = NULL;
return -3;
}

mysql_free_result(query_result);
szSql = NULL;
return 0;
}

可将mysqlfunc.c copy到脚本路径下,在globals.h中引用:
// Include Files
#include "lrun.h"
#include "lrd.h"
#include "web_api.h"
#include "lrw_custom_body.h"
#include "my_api.c"
#include "mysqlfunc.c"

安装mysql dll库:
MySQL LoadRunner libraries.zip
解压后
将bin下的dll文件copy到:
D:\Program Files\HP\LoadRunner\bin
将include下的文件copy到:

D:\Program Files\HP\LoadRunner\include

MySQL LoadRunner libraries下载:

http://pan.baidu.com/s/1pL6tNvX

Mysqlfunc.c的更多相关文章

  1. FTS5与DIY

    此文已由作者王荣涛授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. FTS5简介 前文已经介绍了FTS3/FTS4,本文着重介绍它们的继任者FTS5. FTS5是在SQLite ...

  2. APUE之第5章——标准I/O库

    一.知识回顾:文件I/O 文件 I/O 是不带缓冲的 I/O(unbuffered I/O),指每个 read 和 write 都调用内核中的一个系统调用. 对于内核而言,所有打开的文件都通过文件描述 ...

随机推荐

  1. Docker容器内服务自启

    创建容器时需要配置--privileged和容器启动后执行的命令为/sbin/init/. docker run -d -it --name example -p 3308:3306 -p 2080: ...

  2. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  3. 转 SQL连接查询语句(内、外、交叉和合并查询)

    转 http://blog.csdn.net/u010011371/article/details/50596535 1.内连接 (INNER JOIN) 内连接也称自然连接,它是根据两个或多个表中的 ...

  4. BZOJ 4031: [HEOI2015]小Z的房间 (矩阵树定理 板题)

    背结论 : 度-邻 CODE1 O(n3logn)O(n^3logn)O(n3logn) #include <bits/stdc++.h> using namespace std; typ ...

  5. SpringBoot中注入RedisTemplate实例异常解决(转)

    最近,在项目开发过程中使用了RedisTemplate,进行单元测试时提示“Field redisTemplate in com.example.demo1.dao.RedisDao required ...

  6. python中的堆和栈

    内存中的堆栈和数据结构堆栈不是一个概念,可以说内存中的堆栈是真实存在的物理区,数据结构中的堆栈是抽象的数据存储结构.内存空间在逻辑上分为三部分:代码区.静态数据区和动态数据区,动态数据区又分为栈区和堆 ...

  7. vue、Element 点击按钮以弹窗形式预览pdf文件

    直接上代码吧 <div > <el-button type="success" size="small" @click="isVie ...

  8. js获取服务器端时间

    第一种: $.ajax({ type:"OPTIONS", url:"/", complete:function(x){ var date = x.getRes ...

  9. Ubuntu 保存文件时报E212

    命令输入: vim test/conf.conf 出现如下报错:  步骤一: 没有足够的权限!使用如下代码尝试: :w !sudo tee % > /dev/null 如果步骤一没有解决问题,尝 ...

  10. React事件,修改this.state的值

    1.React中绑定事件 React中绑定事件格式: onClick = { function } React中绑定事件的标准用法: import React from 'react' export ...