简体   繁体   English

mysql事务不适用于innodb表

[英]mysql transaction not working with innodb tables

i write this but transaction not working and i also convert both tables in innodb type can any one guide me whats wrong in my coding or another alternative of transaction. 我写这篇文章,但交易不起作用,我也将两个表都转换为innodb类型,任何人都可以指导我编码或另一种替代交易方式出了什么问题。

mysql_query("begin;");
  $query1 = mysql_query("ALTER TABLE products ADD COLUMN {$_POST[fields]} VARCHAR(60)");

  $query2 = mysql_query("INSERT INTO fields (cid5,fields,field_title,field_type)
                      VALUE ('$_POST[cid]','$_POST[fields]','$_POST[field_title]','$_POST[field_type]')");                

if (($query1)&&($query2)) {mysql_query("commit;");}
else {mysql_query("rollback;");}

}

i am using mysql 5.1.69-cll 我正在使用mysql 5.1.69-cll

ALTER TABLE is a DDL (Data Definition Language) statement; ALTER TABLE是DDL(数据定义语言)语句; which is not transactional in MySQL innodb engine. 在MySQL innodb引擎中不是事务性的。 INSERT is a DML statement (Data Manipulation Language), which is transactional. INSERT是DML语句(数据处理语言),它是事务性的。 Because one statement isn't transactional and one is, the two shouldn't be combined in a transaction. 因为一个语句不是事务性语句,而一个语句是事务性语句,所以不应将这两个语句合并在事务中。

Quoting from the MySQL manual: 引用MySQL手册:

Some statements cannot be rolled back. 某些语句无法回滚。 In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines. 通常,这些语句包括数据定义语言(DDL)语句,例如创建或删除数据库的语句,创建,删除或更改表或存储例程的语句。

You should design your transactions not to include such statements. 您应设计您的交易不包含此类声明。 If you issue a statement early in a transaction that cannot be rolled back, and then another statement later fails, the full effect of the transaction cannot be rolled back in such cases by issuing a ROLLBACK statement. 如果您在事务中提早发出了无法回滚的语句,然后又有另一个语句失败,则在这种情况下,不能通过发出ROLLBACK语句来回滚事务的全部效果。

http://dev.mysql.com/doc/refman/5.6/en/cannot-roll-back.html http://dev.mysql.com/doc/refman/5.6/en/cannot-roll-back.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM