메뉴 건너뛰기

프로그램언어

조회 수 6031 추천 수 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 07Mar
    by
    2017/03/07 Views 20061 

    파일 이름에서 확장자 추출마스터

  2. No Image 06Mar
    by
    2017/03/06 Views 20184 

    파일 업로드 (중복처리)

  3. No Image 14Apr
    by
    2015/04/14 Views 25334 

    파일 삭제

  4. No Image 08Jan
    by
    2019/01/08 Views 1610 

    파일 및 데이타베이스 백업

  5. No Image 19Jun
    by
    2020/06/19 Views 618 

    파일 다운로드 함수(멀티 이어받기/속도제한)

  6. No Image 26Mar
    by
    2021/03/26 Views 243 

    파일 output을 return 하기

  7. No Image 08Jan
    by
    2019/01/08 Views 1226 

    파일

  8. No Image 08Jul
    by
    2021/07/08 Views 322 

    특정일의 주차 구하기

  9. No Image 26Mar
    by
    2014/03/26 Views 21623 

    특수문자 없애는 정규표현식

  10. No Image 22Aug
    by
    2016/08/22 Views 20732 

    템플릿 관련 정보

  11. No Image 16Jan
    by
    2019/01/16 Views 1249 

    태그 또는 멘션 소스 뽐아내기방법

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

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

  13. No Image 27Mar
    by
    2021/03/27 Views 231 

    클래스와 인스턴스 그리고 메소드 만들기

  14. No Image 25Mar
    by
    2021/03/25 Views 270 

    큰따옴표(") 와 작은따옴표(')

  15. No Image 19Jul
    by 조쉬
    2018/07/19 Views 6031 

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

  16. No Image 27Feb
    by
    2014/02/27 Views 29211 

    쿠키변수받기

  17. No Image 23Nov
    by
    2020/11/23 Views 314 

    쿠키 확인 후 만료시 세션 파괴하는 방법

  18. No Image 26Mar
    by
    2021/03/26 Views 307 

    콜론 연산자

  19. No Image 12Jan
    by
    2023/01/12 Views 213 

    코드 생성 하기

  20. No Image 07Mar
    by
    2017/03/07 Views 21131 

    체크박스, post 로 넘기고 받아서 다시 체크하기, checkbox

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

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved