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();
}
}
参考例子
[url]http://www.lampdeveloper.co.uk/mysql/using-mysql-transactions-in-cakephp.html[/url]
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");
例子
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();
}
}
参考例子
[url]http://www.lampdeveloper.co.uk/mysql/using-mysql-transactions-in-cakephp.html[/url]
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");