【发布时间】:2020-07-10 04:51:28
【问题描述】:
所以我试图通过使用事务来运行查询,但它不工作,我确实检查了所有帖子,但似乎没有修复工作!每当我删除事务时,插入查询就可以正常工作。
这是控制器:
public function addEmployee(){
$field = array(
'NomClient'=>$this->input->post('fullName'),
'TelClient'=>$this->input->post('tel'),
'WilayaClient'=>$this->input->post('wilaya'),
'CommuneClient'=>$this->input->post('commune'),
'AdresseClient'=>$this->input->post('adresse'),
'StatusID'=>$this->input->post('statusCommande'),
'TelevendeuseID'=>$this->input->post('televendeuse')
);
$result= $this->m->addEmployee($field);
$msg['success'] = false;
$msg['type'] = 'add';
if($result){
$msg['success'] = true;
}
echo json_encode($msg);
}
我的模特:
public function addEmployee($field){
$this->db->trans_start();
return $this->db->insert('Clients',$field);
$this->db->trans_complete();
}
请注意,当我将模型切换到:
public function addEmployee($field){
return $this->db->insert('Clients',$field);
}
记录插入成功!这意味着交易有问题。我目前正在使用一个查询来测试它是否有效,因此我可以在此之后多次使用。请注意,这些表是 InnoDB 表,因此问题不在于表类型。请帮帮我!
【问题讨论】:
-
当您只进行一次查询时,为什么还要使用事务?似乎有点无意义?
-
你在
$this->db->trans_complete();之前有一个return,所以它永远不会被执行。
标签: php mysql database codeigniter