Programming Reference/Librarys
Question & Answer
Q&A is closed
my_bool mysql_autocommit(MYSQL *mysql, my_bool mode)
mysql_autocommit set the autocommit
0 is off
1 is on
compile with gcc mysql_autocommit.c -o mysql_autocommit `mysql_config –cflags –libs` -Wall
#include <stdio.h> /* including standard library */ #include <mysql/mysql.h> MYSQL *my; MYSQL_ROW row; MYSQL_RES *mysql_res; int main( void ){ char host[20]; char user[20]; char pass[20]; my = mysql_init(NULL); sprintf(host,"localhost"); sprintf(user,"username"); sprintf(pass,"password"); if (my == NULL ) { printf("Cant initalisize MySQL\n"); return 1; } if( mysql_real_connect (my,host,user,pass,NULL,0,NULL,0) == NULL) { printf("Error cant login\n"); } else { printf("Login correct\n"); } mysql_select_db(my,"test"); // select DB mysql_autocommit(my, 1); // set autocommit to ON mysql_query(my, "SELECT @@autocommit"); mysql_res = mysql_store_result(my); row = mysql_fetch_row (mysql_res); // fetch the result printf("autocommit is: %s\n" "0 = off\n1 = on\n", row[0]); mysql_close(my); return 0; }
Login correct autocommit is: 1 0 = off 1 = on