有关事务控制
上传图片,同时保存路径到数据库,怎么建立这个事务控制?
$this->db->trans_start();
$this->db->insert('t_photos', $data);
if(move_uploaded_file($file,$path."/".$name)){
$this->db->trans_complete();
}
可以吗 手册说的很明了
http://codeigniter.org.cn/user_guide/database/transactions.html Running Transactions ManuallyIf you would like to run transactions manually you can do so as follows:
$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();
}
谢谢,没在意这个 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是不存在的,也就是说。第二个查询是有问题的。
我使用了事务。但为什么。 第一条语句还是执行了。 更新了我的数据。? 成功了。。原来忘记了最重要的这个。。
:"在MySQL中,你需要用InnoDB或BDB表而不是更常用的MyISAM。大多数其它的数据库平台都原生支持事务。
"
页:
[1]