public function createCategory($account, $title) { $db = new Database(); $data = array($account, $title); $data = $db->execute("SELECT * FROM categories WHERE account = ? AND title = ?", $data); $data->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'CategoryEntity'); $categoryEntity = $data->fetch(); if ($categoryEntity) { return $categoryEntity; } else { $categoryEntity = new CategoryEntity(); $categoryEntity->setAccount($account); $categoryEntity->setTitle($title); $categoryEntity->persist(); return $categoryEntity; } }