`
icrwen
  • 浏览: 261593 次
  • 性别: Icon_minigender_2
  • 来自: 济南
社区版块
存档分类
最新评论

cakephp工作笔记17---mysql事务篇

    博客分类:
  • php
阅读更多
cakephp1.3版本开始支持事务操作:
例子
function delGranary($deletenode,$children)
    {
      $db =& ConnectionManager::getDataSource($this->useDbConfig);
      #start the transaction 
  $db->begin($this); 

try{
if($this->delete($deletenode))
{
if($this->GranaryMonitorConfig->query("delete from granary_monitor_configs where Granary_id=69"))
return $db->commit($this);
}
else throw new Exception('Model did not delete');
     
}
   catch (Exception $e) {
    $db->rollback();
   
  
}
    }
参考例子
http://www.lampdeveloper.co.uk/mysql/using-mysql-transactions-in-cakephp.html


Changing model's table in model or in controller
如果模型之间没有关联关系,而又要在模型中使用另外一个表时,可以使用model的方法setSource来改变模型对象关联的表
Sets a custom table for your controller class. Used by your controller to select a database table.
例如:$this->setSource("points_infos");
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics