Loadrunner连接Mysql数据库
分别添加到Loadrunner bin目录和include目录下
2、vuser_init
#include "Ptt_Mysql.h" vuser_init() { lr_load_dll ("libmysql.dll"); #define MYSQLSERVER "192.168.1.104" #define MYSQLUSERNAME "root" #define MYSQLPASSWORD "123456" #define MYSQLDB "ultrax" #define MYSQLPORT "3306" }
3、Action
Action() { char sqQuery[512]; //定义一个字符数组存储查询的sql语句 int i; MYSQL *Mconn; //mysql连接字符串 Mconn = lr_mysql_connect(MYSQLSERVER, MYSQLUSERNAME, MYSQLPASSWORD, MYSQLDB, atoi(MYSQLPORT));//创建连接 sprintf(sqQuery, "select username,email from pre_ucenter_members ");//查询论坛用户 lr_mysql_query(Mconn, sqQuery);//执行sql语句 sprintf(sqQuery,"insert into pre_ucenter_members(username,password,email) values('qq','123456','qq@qq.com')");//插入数据 lr_mysql_query(Mconn, sqQuery); sprintf(sqQuery,"update pre_ucenter_members set username='dd' where username='qq' ");//更改用户名qq为dd lr_mysql_query(Mconn, sqQuery); sprintf(sqQuery,"delete from pre_ucenter_members ORDER BY uid desc LIMIT 1");//删除最后添加的一条数据 lr_mysql_query(Mconn, sqQuery); //断开数据库连接 lr_mysql_disconnect(Mconn); return 0; }