首页 > 代码库 > Loadrunner连接Mysql数据库
Loadrunner连接Mysql数据库
1、库文件下载地址:http://files.cnblogs.com/files/xiaoxitest/MySQL_LoadRunner_libraries.zip
#define MYSQLSERVER "192.168.1.106"
#define MYSQLUSERNAME "root"
#define MYSQLPASSWORD "123456"
#define MYSQLDB "test"
#define MYSQLPORT "3306"
#include "Ptt_Mysql.h"
vuser_init()
{
return 0;
}
3.Action
Action()
{
char sqQuery[512]; //定义一个字符数组存储查询的sql语句
int i;
MYSQL *Mconn; //mysql连接字符串
lr_load_dll("libmysql.dll");
Mconn = lr_mysql_connect(MYSQLSERVER, MYSQLUSERNAME, MYSQLPASSWORD, MYSQLDB, atoi(MYSQLPORT));//创建连接
sprintf(sqQuery, "SELECT * FROM test1; ");//查询test1表数据
lr_mysql_query(Mconn, sqQuery);//执行sql语句
sprintf(sqQuery,"INSERT INTO test1 VALUES(2,‘bb‘,‘222222‘);");//插入数据
lr_mysql_query(Mconn, sqQuery);
sprintf(sqQuery,"UPDATE test1 SET uname=‘aaa‘ WHERE id=1; ");//更改用户名aa为aaa
lr_mysql_query(Mconn, sqQuery);
sprintf(sqQuery,"DELETE FROM test1 WHERE id=1;");//删除
lr_mysql_query(Mconn, sqQuery);
//断开数据库连接
lr_mysql_disconnect(Mconn);
return 0;
}
4.Vuser_end
vuser_end()
{
return 0;
}
Loadrunner连接Mysql数据库