This is a test case that was written a long time ago, to check the number of data inserted into the MySQL database, and to see how the database is performing? Whether the server will be fully written soon.
Pre-preparatory work: Mysql database setup, Loadrunner,libmysql.dll and Web search a loadrunner access to mysq Public library.
Step1:mysql Database Setup (this will not detail how to install the MYSQ database and create the table)
ip:192.168.1.100
Access Name: Root
The password is: 123456
The database name is: t3db
The access port is: 3306
This is the information about the database!
How does Step2:loadrunner connect to MySQL?
The following are all on the Internet to find the original code, not my creation (forget who the author is, sorry!) )
IntRcIntDb_connection;Char *server ="192.168.1.100";//The IP address of the databaseChar *user ="Root";//Database Access User NameChar *password ="123456";//PasswordChar *database ="T3db";//Database nameint port =3306;//Access Portint unix_socket =NULL;int flags =0;char**Result_row;IntQuery_result;Char szsql[256];IntMysqlinit () {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 (); }ReturnRC;}IntMysqlunit () {//Free MySQL ResourcesMysql_close (db_connection);Return0;}int Insertvalue (char*query) {rc =mysql_query (Db_connection,query);if (rc! =0) {Lr_error_message ("%s", Mysql_error (db_connection));
} query =NULL;ReturnRC;}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-2char **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 NULL; return 0
Here are a few common functions that everyone knows what they are doing.
How do you write in Step3:loadrunner?
1. Add Libmysql.dll to your project
2. Add the public library to your public
3, Vuser_init
Vuser_init () { 0; Mysqlinit (); // Initialize database 0;}
4, Vuser_end
Vuser_end () { mysqlunit (); // anti-initialization 0;}
5. Action
Action () {IntResultvalue;Char cindex[10];Char onceaccount[1024];Char insertquery[22584]; index = index +1;//Combine the SQL statement strcpy (InsertQuery, which inserts the database"INSERT into ' t3db ' "role" (GroupID, RoleName, account, Baseinfo, Extinfo, lastmodify) VALUES (' 1 ', '"); strcat (InsertQuery, lr_eval_string ("{Account}")); strcat (InsertQuery, itoa (index, CIndex,10)); strcat (InsertQuery,"', ' q1031 ', ' 111 ', ' 111 ', ' 2013-02-28 20:42:33 ')"); strcat (InsertQuery,";"); Lr_start_transaction ("Insert "); Resultvalue = Insertvalue (InsertQuery); // call the Insert function if ( Resultvalue! = 0 "insert" ,lr_fail);} else {lr_end_transaction ( "insert" ,lr_pass); } Sleep (100return 0
This is the whole process ...
LoadRunner accessing MySQL database (GO)