Пример #1
0
 public function getAllCategory()
 {
     $categoryArray = array();
     /* try
        { */
     $sql = "SELECT M02CATEGORYID as id, label,startage,endage,gender FROM M02_CATEGORY order by M02CATEGORYID desc";
     $values = $this->db->query($sql);
     if (is_array($values) || is_object($values)) {
         include_once '../bo/CategoryBO.php';
         foreach ($values as $row) {
             // $categoryArray[] = $row['id'];
             $category = new CategoryBO();
             $category->setId($row['id']);
             $category->setLabel($row['label']);
             $category->setStartAge($row['startage']);
             $category->setEndAge($row['endage']);
             $category->setGender($row['gender']);
             //echo $category;
             $categoryArray[] = $category;
         }
     }
     /* }
        catch(PDOException $e)
        {
            echo $e->getMessage();
            return null;
        } */
     return $categoryArray;
 }
Пример #2
0
$data = json_decode(file_get_contents("php://input"));
//echo $data->category;
$pdo = DbUtil::connect();
$categoryDao = new CategoryDao($pdo);
//echo '{"message":'. $data->category .'}';
if ($data->btn_action == 'save') {
    try {
        $category = $data->category;
        $startAge = $data->startAge;
        $endAge = $data->endAge;
        $gender = $data->gender;
        //$contact = $_POST['contact_no'];
        $categoryBO = new CategoryBO();
        $categoryBO->setLabel($category);
        $categoryBO->setStartAge($startAge);
        $categoryBO->setEndAge($endAge);
        $categoryBO->setGender($gender);
        if ($categoryDao->create($categoryBO)) {
            echo json_encode('{"message":"success"}');
        } else {
            echo json_encode('{"message":"failure"}');
        }
    } catch (Exception $e) {
        $msg = 'failure' . $e->getMessage() . $e->getFile() . $e->getLine();
        $msg = str_replace("\\", "\\\\", $msg);
        $msg = htmlspecialchars($msg);
        echo json_encode('{"message":"' . $msg . '"}');
    }
} else {
    if ($data->btn_action == 'getAllCategory') {
        try {