setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->query($sql); $stmt->bindParam("id", $get_id); $stmt->execute(); $coupon = $stmt-> fetchObject(); //$coupons = $stmt->fetchAll(PDO::FETCH_OBJ); $ret= utf8_encode_all($coupon) ; $dbh = null; echo '{"item":'. json_encode($ret) .'}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } function utf8_encode_all($coupon) { if (is_string($coupon)) return utf8_encode($coupon) ; if (!is_array($coupon)) return $coupon; } ?> 餐飲類

優惠券說明