메뉴 건너뛰기

프로그램언어

조회 수 6020 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

쿠폰번호 발행 업데이트판. (간단한 클래스화[PHP4 기준] 등...)

 

 

 

DB

CREATE TABLE `coupon_test` (
  `couponNO` varchar(16) NOT NULL default '',
  `ID` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`couponNO`)
) TYPE=MyISAM;

 

 

쿠폰생성 소스

<?
// Mysql 클래스
class TMySql {
    var $dbconn; // DB 연결 리소스
    var $result; // Query 결과 저장 리소스

  

     // 생성자: DB에 연결
    function TMySQL($Host, $DB, $ID, $PW) {
        $this->dbconn=mysql_connect($Host, $ID, $PW) or die("데이터베이스 연결에 실패하였습니다.<br/>".mysql_error());
        mysql_select_db($DB, $this->dbconn) or die("{$DB}를 사용할 수 없습니다.<br/>".mysql_error());
    }

 

    // Query 실행. 결과를 $this->result 에 저장
    function Query($SQL) {
        mysql_real_escape_string($SQL);
        $this->result=mysql_query($SQL, $this->dbconn);
        if (!$this->result) die('INVALID QUERY: '.mysql_error());  
    }

 

    // Query 결과의 갯수 반환
    function Count() {
        return mysql_num_rows($this->result);
    }
}

 


// 쿠폰번호 클래스
class TCoupon {
    var $coupon_len;  // 쿠폰길이
    var $arr_no;      // 숫자배열
    var $arr_alphabet;// 알파벳배열

 

    // 생성자: 쿠폰길이를 받아 멤버에 세팅하고, 숫자와 알파벳배열을 세팅
    function TCoupon($CouponLength=16) {
         $this->coupon_len=$CouponLength;

         // 숫자
         for ($i=Ord('0'); $i<=Ord('9'); $i++) $this->arr_no[]=Chr($i);
         // 알파벳
         for ($i=Ord('A'); $i<=Ord('Z'); $i++) $this->arr_alphabet[]=Chr($i);    
    }

 

    // 쿠폰번호 반환
    function GetCoupon() {
         $result_str="";

         $len_no=count($this->arr_no);
         $len_alphabet=count($this->arr_alphabet);

 

         for ($i=0; $i<$this->coupon_len; $i++){
             // 랜덤을 돌려 0 이면 숫자, 1 이면 알파벳
             if (rand(0,1)==0) $result_str.=$this->arr_no[rand(0,$len_no-1)];
             else                 $result_str.=$this->arr_alphabet[rand(0,$len_alphabet-1)];
         } 
         return $result_str;
    }
}

 

 

 

// DB 객체 생성
$MySQL=new TMySQL('localhost', 'db_bloodguy', 'bloodguy', 'nicehide');

// 길이가 16인 쿠폰번호 객체 생성
$Coupon=new TCoupon(16);


// 쿠폰발행 루프 (10000개의 번호를 생성한다고 가정)
$x=0;
while ($x<10000){
    $CouponNo=$Coupon->GetCoupon();

   

    // 해당 번호가 DB 있는 중복번호인가 체크
    $MySQL->Query("select * from coupon_test where couponNO='{$CouponNo}'");
    // 중복번호가 아니라면 DB 에 넣음
    if ($MySQL->Count==0) {
         $MySQL->Query("insert into coupon_test VALUES ('{$CouponNo}' ,'')");
         //echo $CouponNo."<br>";
         $x++;
    }
    // 중복번호라면 다시
    else continue;
} // while ($x<10000)
?>



  1. No Image 14Sep
    by
    2018/09/14 Views 3548 

    PHP에서의 대칭 암호화/복호화 ― 간단한 예제에서 DB 입/출력까지

  2. No Image 29Aug
    by
    2018/08/29 Views 2447 

    PHP에서 자료, 데이터의 타입을 확인하는 방법, gettype()

  3. No Image 29Aug
    by
    2018/08/29 Views 2693 

    PHP에서 모든 세션 정보를 화면에 출력하는 방법

  4. No Image 29Aug
    by
    2018/08/29 Views 3933 

    한글이 깨져서 나올 때 - iconv

  5. No Image 29Aug
    by
    2018/08/29 Views 2429 

    날짜/시간함수 정리

  6. No Image 24Jul
    by
    2018/07/24 Views 4543 

    웹서버조회 소스

  7. No Image 24Jul
    by
    2018/07/24 Views 7320 

    헤더이용 다운로드 받을시 바로열기부분 소스

  8. No Image 24Jul
    by
    2018/07/24 Views 5741 

    키를 이용한 암호화/복호화 함수입니다.

  9. No Image 24Jul
    by
    2018/07/24 Views 4798 

    MySQL테이블의 내용을 엑셀파일(xls)로 다운로드 하기

  10. No Image 24Jul
    by
    2018/07/24 Views 4523 

    날짜계산 몇일까지.. [ ex)4 일전 new 표시 ]

  11. No Image 24Jul
    by
    2018/07/24 Views 4767 

    게시판 내용 숨김 클릭시 내용 출력 [ 참고 ]

  12. No Image 24Jul
    by
    2018/07/24 Views 4584 

    마우스 오버시 사진변환, 파일에러시 대체이미지 적용(소스일부)

  13. No Image 19Jul
    by
    2018/07/19 Views 6643 

    PHP 소스코드 인코딩(암호화)하기

  14. No Image 19Jul
    by
    2018/07/19 Views 5582 

    gcm 푸시 알림 php 테스트

  15. No Image 19Jul
    by
    2018/07/19 Views 5450 

    PHP 특정 디렉토리에 있는 파일 갯수 구하기

  16. No Image 19Jul
    by
    2018/07/19 Views 6044 

    fcm 푸시 알림 php 테스트

  17. No Image 19Jul
    by 조쉬
    2018/07/19 Views 6020 

    쿠폰번호 발행 업데이트판. (간단한 클래스화[PHP4 기준] 등...)

  18. No Image 04Jul
    by
    2018/07/04 Views 5230 

    날짜, 시간 포맷하기 (PHP)

  19. No Image 04Jul
    by
    2018/07/04 Views 8454 

    AJAX를 활용하여 JSON 댓글 처리하기 (PHP)

  20. No Image 04Jul
    by
    2018/07/04 Views 5793 

    PHP 파일크기 단위 붙이기 (용량 변환) file size conversion source code

Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved