Home > Database > Mysql Tutorial > c语言mysql数据库事务开始、提交、回滚范例_MySQL

c语言mysql数据库事务开始、提交、回滚范例_MySQL

WBOY
Release: 2016-06-01 12:58:52
Original
2727 people have browsed it

1、 事务提交模式修改:修改数据库提交模式为0[手动提交]

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "set autocommit=0;", 17 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "关闭自动提交模式失败[%d][%s]", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

2、 事务开始

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "start transaction;", 18 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "建立事务失败[%d][%s]", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

3、 事务回滚

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "rollback;", 9 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "事务回滚失败[%d][%s]", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

 

4、 事务提交

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "commit;", 7 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "提交事务失败[%d][%s]\n", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template