1. library file: Http://files.cnblogs.com/files/xiaoxitest/MySQL_LoadRunner_libraries.zip
Add to LoadRunner Bin directory and include directory, respectively 2, Vuser_init
#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]; Defines a character array to store the SQL statement for the query
int i;
MYSQL *mconn; MySQL connection string
Lr_load_dll ("Libmysql.dll");
Mconn = Lr_mysql_connect (MySQLServer, Mysqlusername, Mysqlpassword, MySQLdb, Atoi (Mysqlport));//Create Connection
sprintf (Sqquery, "select * from Test1;"); /Query Test1 table data
Lr_mysql_query (Mconn, sqquery);//Execute SQL statement
sprintf (Sqquery, "INSERT into Test1 VALUES (2, ' BB ', ' 222222 ');"); /Insert Data
Lr_mysql_query (Mconn, sqquery);
sprintf (Sqquery, "UPDATE test1 SET uname= ' aaa ' WHERE id=1; ");//change user name AA to AAA
Lr_mysql_query (Mconn, sqquery);
sprintf (Sqquery, "DELETE from Test1 WHERE id=1;"); /delete
Lr_mysql_query (Mconn, sqquery);
Disconnecting database connections
Lr_mysql_disconnect (Mconn);
return 0;
}
4.vuser_end
Vuser_end ()
{
return 0;
}
LoadRunner connecting MySQL Database