Home > Backend Development > PHP Tutorial > 有熟悉事务或PDO的吗?老是回滚,删除不掉数据解决方法

有熟悉事务或PDO的吗?老是回滚,删除不掉数据解决方法

WBOY
Release: 2016-06-13 13:50:44
Original
959 people have browsed it

有熟悉事务或PDO的吗?老是回滚,删除不掉数据
数据库类型:sqlite 
没有提示错误,一行一行测试,的确没有错误,为什么老是回滚? 老是回滚,删除不掉数据 
大家推测原因是什么?
以下是说明性代码:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
  $king->db->connect(); //连接数据库 $link为数据库连接句柄。 
 $king->db->link->beginTransaction();//回滚起始点 
 if($rs1=$king->db->getRows_number('%s_newsContent',"newsID in($newsID)")) 
 { 
  if($rs2=$king->db->query("delete from %s_newsContent where newsID in($newsID)")) 
  { 
   $s.="删除新闻内容成功![".$rs2."/".$rs1."条]<br>"; 
  } 
  else 
  { 
   lzj_message('删除新闻内容失败','javascript:history.go(-1)');    
  } 
 } 
 if($rs1=$king->db->getRows_number('%s_rss',"idValue in($newsID) and tableName='news' and idName='newsID'")) 
 { 
   
  if($rs2=$king->db->query("delete from %s_rss where tableName='news' and idName='newsID' and idValue in($newsID)")) 
  { 
    
   $s.="删除新闻RSS成功![".$rs2."/".$rs1."条]<br>"; 
  } 
  else 
  { 
   lzj_message('删除新闻RSS失败','javascript:history.go(-1)'); 
  } 
 } 
 if($rs=$king->db->query("delete from %s_news where newsID in(".$newsID.")")) 
 { 
  lzj_message("删除成功![".$rs."条]<br>".$s,$pageUrl);   
 } 
 else 
 { 
  lzj_message('删除新闻失败','javascript:history.go(-1)'); 
 }  
 $king->db->link->commit();//回滚结束点 


Copy after login


------解决方案--------------------
感觉你这种写法有问题.
你可以事物开始时,设立一个标识如flag=true;

if( $flag ){
你的操作........
} else{
..............
$flag = false;
}
同上面一样继续下一个操作


最后
if( $flag ){
提交事物
}else{
 
回滚
}
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