I am trying to store a array into database(SQL Server), in that array I am getting some values from UI, and some values fetched from Model. Here my problem is with second one only... The values coming from UI is getting inserted, but the values coming from model are in object notation.... It can't store into a single variable...so that the data is not even store into database... and it raises the error
Object of class stdClass could not be converted to string
Here is my code...
Model
public function getCustcode($customer)
{
return $query = $MainDB->query("SELECT custcode from CRM_CustomerEvents_View where custname = '".$customer."'")->row();
}
Controller:
public function addEvent()
{
$name = $this->input->post("name",TRUE);
$start_date = $this->input->post("start_date", TRUE);
$end_date = $this->input->post("end_date", TRUE);
$customer = $this->input->post("customer",TRUE);
$custcode = $this->Calendarmodel->getCustcode($customer);
$tranno = $this->input->post("transno",TRUE);
$leadid = $this->Calendarmodel->getLeadID($tranno);
}
$data = array(
"title" => $name,
"start_event" => $start_date,
"end_event" => $end_date,
"custcode" => $custcode,
"Leadid" => $leadid,
);
It raises the error
Object of class stdClass could not be converted to string
then I changed like this
$data = array(
"title" => $name,
"start_event" => $start_date,
"end_event" => $end_date,
"custcode" => $custcode[0]['custcode'], //'100287',//
"Leadid" => $leadid[0]['Leadid'] //'10070'//
);
It generates the error:
Cannot use object of type stdClass as array
If I use json_encode($custcode) in static way(to test) and it gives me the data as:
"{"custcode":"100287"}"
Please, can anyone give any solution to handle this object data coming from Model...
var_dump($custcode);- Giacomo M