prepare('INSERT INTO `' . Utils::table('slot') . '` (poll_id, title, moments) VALUES (?, ?, ?)'); foreach ($choices as $choice) { // We prepared the slots (joined by comas) $joinedSlots = ''; $first = true; foreach ($choice->getSlots() as $slot) { if ($first) { $joinedSlots = $slot; $first = false; } else { $joinedSlots .= ',' . $slot; } } // We execute the insertion if (empty($joinedSlots)) { $prepared->execute(array($poll_id, $choice->getName(), null)); } else { $prepared->execute(array($poll_id, $choice->getName(), $joinedSlots)); } } } function listByPollId($poll_id) { $prepared = $this->prepare('SELECT * FROM `' . Utils::table('slot') . '` WHERE poll_id = ? ORDER BY title'); $prepared->execute(array($poll_id)); return $prepared->fetchAll(); } }