[英]mysql_query(“ROLLBACK”); does not work
This code do a transaction with all queries stored in $in. 此代码使用存储在$ in中的所有查询进行事务。 for example $in = "Query1; Query2; Query3;" 例如$ in =“ Query1; Query2; Query3;”
When one of them fails, it is rolled back but has no effect and the queries that had no errors are inserted into the database 当其中之一失败时,它将回滚但没有效果,并且将没有错误的查询插入数据库中
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('ERR');
}
mysql_select_db('db445123652');
mysql_query("START TRANSACTION");
$strlen = strlen( $in);
$ini = 0;
for( $i = 0; $i <= $strlen; $i++ ) {
$char = substr( $in, $i, 1 );
if($char == ';' )
{
$resul = mysql_query(substr( $in, $ini, $i ));
if(!$resul)
{
echo mysql_error();
mysql_query("ROLLBACK");
echo 'Rollback';
break;
}
else{
$ini = $i + 1;
}
}
}
if($i==($strlen+1) && $resul)
{
echo 'OK';
mysql_query("COMMIT");
}
The database is in a 1&1 host and I acces through phpmyadmin. 该数据库位于1&1主机中,我通过phpmyadmin访问。
check for your database to table engine, if it is set to InnoDb or not. 检查数据库到表引擎是否已设置为InnoDb。
there is difference between MyISAM and Innodb refer http://www.rackspace.com/knowledge_center/article/mysql-engines-myisam-vs-innodb MyISAM和Innodb之间有区别,请参见http://www.rackspace.com/knowledge_center/article/mysql-engines-myisam-vs-innodb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.