1、下载Lr的mysqllib库
2、将MySQLLoadRunnerlibraries解压后的include和bin目录的文件放到loadrunner的安装目录对应的include和bin目录下。
3、 编写代码
//Vuser_init
#define MYSQLSERVER "192.168.1.67" //mysql的ip
#define MYSQLUSERNAME "root" //用户名
#define MYSQLPASSWORD "1" //密码
#define MYSQLDB "testdb" //数据库
#define MYSQLPORT "3306" //端口
#include "Ptt_Mysql.h" //引入mysql lib的h文件
vuser_init()
{
return 0;
}
//Action
Action()
{
char chQuery[128];
MYSQL *Mconn;
lr_load_dll("libmysql.dll"); //引入libmysql的dll
Mconn = lr_mysql_connect(MYSQLSERVER, MYSQLUSERNAME, MYSQLPASSWORD, MYSQLDB, atoi(MYSQLPORT));//connection mysql
sprintf(chQuery, "update emp set comm=comm+1 where empno=1001;"
);
lr_mysql_query(Mconn, chQuery);//执行sql
lr_mysql_disconnect(Mconn);//close connection
return 0;
}