"1" need to use the libmysql.dll dynamic link library to MySQL, so need to install MySQL, note: The local installation of MySQL best and MySQL database server version consistent; (this time using MySQL 5.6)
"2" LoadRunner Select "Cvuser" agreement;
"3" select "File" → "add Files to Script", the MySQL Server 5.6/lib under the Libmysql.dll load, so load, compared with the absolute path in the script, portability is better;
Then you can see that the left file has been added;
"4" Use the function in Libmysql.dll to complete the script;
"5" When the Insert SQL statement contains Chinese, you need to set the character set to GBK, to prevent Chinese garbled: mysql_query (db_connection,lr_eval_string ("SET NAMES GBK"));
Full code:
(1) vuser_init.c file contents
int rc; int db_connection; //Database Connection int query_result; // Query result set MYSQL_RESchar ** result_row; // query data row char *server = "*.*.*.*"; //pressure test Database IP address char *user = "test"; //pressure test Database login name char *password = "test"; //test Database login Password char *database = "TESTDB"; //pressure test database name int port = 8066; //pressure Measurement database port number int unix_socket = null; int flags = 1; vuser_init () { // Locate the location of the Libmysql.dll. If MySQL is installed and the DLL file is imported into the script, it can be load directly without the need for path rc = lr_load_dll ( "Libmysql.dll"); if (rc != 0) { lr_error_message ("CouLd not load libmysql.dll "); lr_abort (); } // create a MySQL object db_connection = Mysql_init (NULL); if (db_connection == null) { lr_error_message ("Insufficient memory"); lr_abort (); } // Connect to MySQL database rc = mysql_real_connect (db_connection, server, user, password, database, port, unix_socket, flags); if (RC == null) { lr_error_ Message ("%s", mysql_error (db_connection)); mysql_close (db_ Connection); lr_abort (); } //If the insert data contains Chinese, You will need to set the character set to GBK to prevent Chinese garbled mysql_query (db_connection,lr_eval_string ("Set names  GBK ")); return 0;}
(2) ation.c file contents
Action ()
{
Parametric cus_code and other parameters;
Lr_save_string (lr_eval_string ("INSERT into ' so_customer ' (' ID ', ' CREATOR ', ' create_time ', ' update_time ', ' VERSION ', ' Sync_version ', ' REMARK ', ' UDF ', ' cus_name ', ' cus_code ', ' cus_phone ', ' cus_fax ', ' cus_address ', ' cus_owner_id ', ' Cus_ Owner_name ', ' cus_operation_employee_id ', ' cus_operation_employee_name ', ' settle_method ', ' CONTACT_PERSON ', ' Z_CUS_ ID ', ' STATUS ', ' time ') '
"VALUES (NULL, ' Performance Test Creator ', ' 2017-05-11 19:35:58.000000 ', ' 2017-05-11 19:35:58.000000 ', ' + ', ' 99990000000001 ', NULL, NULL, "
"' {Cus_code} ', ' {cus_code} ', null, ', ' ', ' {ID} ', ' {NAME} ', null, ' ', NULL, ' performance test dedicated ',"
"' 50000003{cus_id} ', ' 1 ', ' 2017-05-05 19:13:55 ');"),
"Paraminsertquery");
rc = mysql_query (db_connection, lr_eval_string ("{paraminsertquery}"));
if (rc!= 0)
{
Lr_error_message ("%s", Mysql_error (db_connection));
Mysql_close (db_connection);
Lr_abort ();
}
return 0;
}
(3) VUSER_END.C file contents
Vuser_end () {mysql_close (db_connection); return 0;}
Note:
① directly to the database into the database, it is recommended that the "Version" field by default to 1, which is sometimes an optimistic lock implementation of one of the way, no value may cause the server to report "optimistic lock" error;
Appendix-----Retention:
The Libmysql.dll dynamic link library provides a number of functions to manipulate a database, broadly divided into the following categories:
The specific parameters of the function and the use of the method can also refer to the Libmysql.dll for the header file mysql.h
The first part controls the class function
Mysql_init () initializing MySQL object
Mysql_options () Setting connection options
Mysql_real_connect () connect to MySQL Database
Mysql_real_escape_string () legalizing the query string
mysql_query () emits a query string that ends with a null character
Mysql_real_query () issue a query string
Mysql_store_result () One-time transfer results
Mysql_use_result () pass-by-line results
Mysql_free_result () Releasing the result set
Mysql_change_user () change user
mysql_select_db () Change the default database
Mysql_debug () Send debug information
Mysql_dump_debug_info () Dump debug information
Mysql_ping () test whether the database is active
Mysql_shutdown () Request database shutdown
Mysql_close () to close the database connection
The second part information gets the class function
Mysql_character_set_name () Gets the default character set
Mysql_get_client_info () Get client information
Mysql_host_info () Get host information
Mysql_get_proto_info () Get protocol information
Mysql_get_server_info () Get server information
Mysql_info () Get additional information for a partial query statement
Mysql_stat () Get Database status
Mysql_list_dbs () Get a list of databases
Mysql_list_tables () Get a list of data tables
Mysql_list_fields () Get the field list
The third Part column class operation function
Mysql_field_count () Gets the number of fields
Mysql_affected_rows () Gets the number of rows affected
MYSQL_INSERT_ID () Gets the ID value of the auto_increment column
Mysql_num_fields () Gets the number of fields in the result set
Mysql_field_tell () Gets the current field position
Mysql_field_seek () Position field
Mysql_fetch_field () Gets the current field
Mysql_fetch_field_direct () Gets the specified field
Mysql_frtch_fields () gets an array of all fields
Mysql_num_rows () Gets the number of rows
Mysql_fetch_lengths () Gets the line length
Mysql_row_tell () Gets the current row position
Mysql_row_seek () Row positioning
Mysql_da Ta_seek () line positioning
Mysql_fetch_row () Get the Forward
Part fourth Threading class operation function
Mysql_list_processes () returns the list of all threads
MYSQL_THREAD_ID () Gets the current thread ID
Mysql_thread_safe () Whether thread mode is supported
Mysql_kill () Kill a thread
Part five error handling class function
Mysql_errno () Get error number
Mysql_error () Get error message
Part six obsolete functions
Mysql_connect ()
mysql_create_db ()
mysql_drop_db ()
Mysql_eof ()
Mysql_reload ()
Mysql_escape_string ()
LoadRunner complete MySQL test by using Libmysql.dll