i'm trying to save DatTime object in MySQL DB. On insert, i have this error :
"An exception occurred while executing 'INSERT INTO event (name_event, desc_event, minimalPrice_event, startDate_event, endDate_event, startHour_event, endHour_event, num_ET) VALUES (?, ?, ?, ?, ?, ?, ?, ?)' with params ["rfreger", "gregregerg", 44, {"date":"2011-01-01 00:00:00","timezone_type":3,"timezone":"Europe/Paris"}, false, false, false, 2]: Catchable Fatal Error: Object of class DateTime could not be converted to string"
I don't understand why the method try to convert the DateTime object to a String
how to fix this problem?
public function save(Event $event) {
$eventData = array(
'name_event' => $event->getName(),
'desc_event' => $event->getDesc(),
'minimalPrice_event' => $event->getMinimalPrice(),
'startDate_event' => $event->getStartDate(),
'endDate_event' => $event->getEndDate(),
'startHour_event' => $event->getStartHour(),
'endHour_event' => $event->getEndHour(),
'num_ET' => $event->getType()
);
if ($event->getNum()) {
// The event has already been saved : update it
$this->getDb()->update('event', $eventData, array('num_event' => $event->getNum()));
} else {
// The event has never been saved : insert it
$this->getDb()->insert('event', $eventData);
// Get the id of the newly created event and set it on the entity.
$id = $this->getDb()->lastInsertId();
$event->setNum($id);
}
}