Welcome Guest, Not a member yet? Register   Sign In
Inserting data into MYSQL using private object of the class
#1

[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 />";
}
}
}
--------------------------------------------------------------------------




Theme © iAndrew 2016 - Forum software by © MyBB