SORU
8 Mayıs 2013, ÇARŞAMBA


nasıl son Ekle codeıgniter active record ekleme sorgusu sonrası kimliği almak için

Bir ekleme sorgusu (aktif kaydı tarzı) bir MySQL tabloya form alanları eklemek için kullanılır. Benim sorgunun dönüş değeri olarak ekleme işlemi için otomatik artan ıd son almak istiyorum ama bazı sorunlarım var! feryat ben ne yaptım!

İç kontrolör:

function add_post(){
    $post_data = array(
        'id'            => '',
        'user_id'   =>  '11330',
        'content'   =>  $this->input->post('poster_textarea'),
        'date_time' => date("Y-m-d H:i:s"),
        'status'        =>  '1'
    );
    return $this->blog_model->add_post($post_data);
}

Ve modelini girin

function add_post($post_data){
    $this->db->trans_start();
    $this->db->insert('posts',$post_data);
    $this->db->trans_complete();
    return $this->db->insert_id();
}

Model add_post dönüşü gibi bir şey!

CEVAP
8 Mayıs 2013, ÇARŞAMBA


Bu deneyin

function add_post($post_data){
   $this->db->insert('posts', $post_data);
   $insert_id = $this->db->insert_id();

   return  $insert_id;
}

Çoklu uçlar halinde kullanabilirsiniz

$this->db->trans_start();
$this->db->trans_complete();

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • LatinNinja99

    LatinNinja99

    28 EKİM 2011
  • Majestic Casual

    Majestic Cas

    28 NİSAN 2012
  • The Bad Tutorials

    The Bad Tuto

    6 EKİM 2009