在 codeigniter 裡的 helper 使用資料庫

如果要在 ci 的 helper 裡面使用資料庫,必須要使用 & get_instance() ,用法如下。

  1. $ci=& get_instance();   
  2. $ci->load->database();    
  3. //do something   
  4. $ci->db->insert('your_table'$data);  

要呼叫資料庫都用 $ci 取代 $this

留言