用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3517|回复: 4
收起左侧

[HELP] 有关事务控制

[复制链接]
发表于 2009-1-5 18:01:51 | 显示全部楼层 |阅读模式
上传图片,同时保存路径到数据库,
怎么建立这个事务控制?


PHP复制代码
$this->db->trans_start();
$this->db->insert('t_photos', $data);
if(move_uploaded_file($file,$path."/".$name)){
     $this->db->trans_complete();
}
复制代码


可以吗
发表于 2009-1-5 18:17:44 | 显示全部楼层
 楼主| 发表于 2009-1-6 09:14:55 | 显示全部楼层
Running Transactions ManuallyIf you would like to run transactions manually you can do so as follows:
PHP复制代码
$this->db->trans_begin();
 
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
 
if ($this->db->trans_status() === FALSE)
{
    $this->db->trans_rollback();
}
else
{
    $this->db->trans_commit();
}
复制代码


谢谢,没在意这个
发表于 2009-12-4 16:43:19 | 显示全部楼层
function index()
{
  $this->db->trans_start();
  $this->db->query('update product set producttype="诺基亚 6720 classi4444c" where id=6');
  $this->db->query('select titles from news limit 20');
  $this->db->trans_complete();
  
  if ($this->db->trans_status() === FALSE)
  {
   $this->db->trans_rollback();
  }
  else
  {
   $this->db->trans_commit();
  }  
}

我这样写了个代码。 。 第一条update是正确的。
第二条sql,select 的titles是不存在的,也就是说。第二个查询是有问题的。
我使用了事务。但为什么。 第一条语句还是执行了。 更新了我的数据。?
发表于 2009-12-4 17:14:59 | 显示全部楼层
成功了。。原来忘记了最重要的这个。。
:"在MySQL中,你需要用InnoDB或BDB表而不是更常用的MyISAM。大多数其它的数据库平台都原生支持事务。
"

本版积分规则