User Tools

Site Tools


c:mysql:mysql.h:mysql_commit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:mysql:mysql.h:mysql_commit [2013/02/25 23:29]
Daniel Gohlke
c:mysql:mysql.h:mysql_commit [2024/02/16 01:12] (current)
Line 5: Line 5:
  
 ==== description of mysql_commit ==== ==== description of mysql_commit ====
-mysql_commit is in work by code-reference.com \\  +mysql_commit Commits the current transaction.  
-if you are faster... don't hasitate and add it+The action of this function is subject to the value of the completion_type system variable. \\ 
 +if the value of completion_type is 2, the server performs a release after terminating a transaction and closes the client connectionThe client program should call mysql_close()
  
 <code c> <code c>
-no example at the moment+#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]; 
 +unsigned long numrows = 0; 
 + 
 +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"); 
 +mysql_autocommit(my, (my_bool)0);   // set autocommit to false 
 + 
 +mysql_query(my, "TRUNCATE TABLE `collection`;"); 
 +mysql_query(my, "INSERT INTO `test`.`collection`" 
 +         " (`id`, `name`, `title`, `published`)" 
 + " VALUES (NULL, 'Debian', 'Debian 4.0', '2011-02-14');"); 
 +mysql_query(my, "SELECT * from collection WHERE 1;"); 
 + 
 +if (mysql_affected_rows(my) >= 1) { 
 +   mysql_rollback(my); 
 +
 +else { 
 +   mysql_commit(my); 
 +
 +  
 +printf("rows affected: %li\n", numrows); 
 + 
 +mysql_res = mysql_store_result(my); 
 +row = mysql_fetch_row (mysql_res);   // fetch the result 
 +numrows = (unsigned long) mysql_num_rows (mysql_res); 
 +printf("rows affected after mysql_commit: %li\n", numrows); 
 + 
 + 
 +mysql_close(my); 
 +return 0; 
 +}
 </code> </code>
  
 ===== output of mysql_commit c example ===== ===== output of mysql_commit c example =====
-    no example at the moment+    Login correct 
 +    rows affected: 0 
 +    rows affected after mysql_commit: 1
  

on the occasion of the current invasion of Russia in Ukraine

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

Impressum Datenschutz