User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:mysql:mysql.h:mysql_autocommit

mysql_autocommit

my_bool mysql_autocommit(MYSQL *mysql, my_bool mode)

description of mysql_autocommit

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;
}

output of mysql_autocommit c example

  Login correct
  autocommit is: 1
  0 = off
  1 = on

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/mysql/mysql.h/mysql_autocommit.txt · Last modified: 2024/02/16 01:12 (external edit)

Impressum Datenschutz