Inserting data into MYSQL using private object of the class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Inserting data into MYSQL using private object of the class (/showthread.php?tid=46838) |
Inserting data into MYSQL using private object of the class - El Forum - 11-16-2011 [eluser]Unknown[/eluser] Hello everyone... I need to insert data from class object to MYSQL database.. But i'm not able to insert private variable data from the class into datbase.. I tried to insert public variable data from the class into database and its working fine.. But i need to declare variable as private only.. So need help!!! -------------------------------------------------------------------------- Controler Code: class Blog extends CI_Controller { public function chhh() { $this->load->model('input_test'); $this->input_test->create_it(); } } -------------------------------------------------------------------------- Model code: class Input_test extends CI_Model { private $name; private $title; function get_title() { return $this->title; } function set_title($test_title) { $this->title = $test_title; } function get_name() { return $this->name; } function set_name($test_name) { $this->name = $test_name; } function create_it() { $input_test_obj = new Input_test(); $input_test_obj->set_title('title here'); $input_test_obj->set_name('name here'); $this->db->insert('gen', $input_test_obj); if($this->db->affected_rows() === 1) { echo "Created!!<br />"; } else { echo "Error while Creating!!<br />"; } } } -------------------------------------------------------------------------- |