• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transactions Question

#1
I would like to know if my code below is OK for the codeigniter database Transactions, I am not sure if the transactions works for update and inserts?

https://www.codeigniter.com/user_guide/d...s-manually

PHP Code:
public function insert_topic()
{
    
$this->db->trans_begin();

    
$topic_data = array(
        
'forum_id' => $this->input->get('fid'),
        
'user_id' => $this->session->userdata('user_id'),
        
'title' => $this->input->post('subject'),
        
'message' => $this->input->post('message'),
        
'date_created' => time()
    );

    
$this->db->set($topic_data);
    
$this->db->insert($this->db->dbprefix 'topics');

    
$topic_id $this->db->insert_id();

    
$forum_data = array(
        
'lastpostdate' => time(),
        
'lastpostid' => $topic_id,
        
'lastpostuserid' => $this->session->userdata('user_id'),
        
'lastpostby' => '',
        
'lastpostsubject' => $this->input->post('subject')
    );

    
$this->db->where('forum_id'$this->input->get('fid'));
    
$this->db->update($this->db->dbprefix 'forum'$forum_data);

    
$forumsread_data = array(
        
'forum_id' => $this->input->get('fid'),
        
'user_id' => $this->session->userdata('user_id'),
        
'date_created' => time()
    );

    
$this->db->insert($this->db->dbprefix 'forumsread'$forumsread_data);

    if (
$this->db->trans_status() === FALSE)
    {
        
$this->db->trans_rollback();
    }
    else
    {
        
$this->db->trans_commit();
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.