Background Image
조회 수 31628 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
php에서 객체를 문자열로 변환해서 DB에 저장할 때가 있다. 이때 주의할 점..
반환 값이 

Returns a string containing a byte-stream representation of value that can be stored anywhere.
바이트 스트림이기 때문에 일반적인 문자열로 생각할 경우 곤란할 경우가 생긴다.
.

If you are serializing an object with private variables, beware. The serialize() function returns a string with null (x00) characters embedded within it, which you have to escape. Not great if you're trying to save objects into a DB...

위의 글과 마찬가지로 private 변수를 사용할 경우
null(x00) 값이 들어가기 때문에 자칫 c나 php 함수를 사용해서 db에 저장하는 경우 중간에 끊기는 경우가 발생할 수 있다.
(가장 좋은 방법은 blob 같은 데이터 타입을 사용하는 것이다.)

테이블의 컬럼은 VARCHAR 형태로 만든 후
base64_encode()를 사용해서 변경하면 객체를 serialize한 값을 사용할 수 있다.

ex)
 -- 테이블 생성
CREATE TABLE "test_bind"(
    "id" integer AUTO_INCREMENT,
    "var" character varying(1073741823)
);



php 예제
 <?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$server = "127.0.0.1";
$port = 33000;
$dbName = 'testdb';
$user = 'dba';
$password = 'cubrid';

/*
CREATE TABLE "test_bind"(
    "id" integer AUTO_INCREMENT,
    "var" character varying(1073741823)
);
*/

class ParserOutput
{
    var $mText = 'test';
    private $mIndexPolicy = '';
    private $displayTitle = false;
}


$po = new ParserOutput();
$value = serialize ( $po );
$value = base64_encode( $value );

$con = cubrid_connect($server, $port, $dbName, $user, $password);
if ($con) {
   echo "connected successfully<br/>";
    
   
   $sql = "insert into test_bind(var) values ( ? )";
   $req = cubrid_prepare( $con, $sql );
   
   print "cubrid_bind()";
   $res = cubrid_bind( $req, 1, $value); print " -- OK<br/>";
   
   $res = cubrid_execute( $req );
   print "result: $res <br/>";
   
   if (cubrid_error_code() > 0) {
    print "ERRORCODE:" . cubrid_error_code() . "<br/>";
    print "ERROR:" . cubrid_error_msg() . "<br/>";
   }

   cubrid_commit($con);
   cubrid_disconnect ($con);
}




TAG •

  1. 문자 코드셋(UTF-8, EUC-KR) 사용시 CUBRID 는?

    Date2010.01.01 Category질의작성 By남재우 Views22398
    Read More
  2. 테이블에 comment 사용하기

    Date2010.01.01 Category기타 By남재우 Views21051
    Read More
  3. cubrid_service.exe 가 CPU 를 지속적으로 일정부분 점유하는 경우

    Date2010.01.01 Category운영관리 By남재우 Views13030
    Read More
  4. 질의편집기 사용시 주의할 점

    Date2010.01.01 CategoryCUBRID 매니저 By남재우 Views13112
    Read More
  5. 타 DB 에서 마이그레이션시 질의 변경 샘플 - CASE 문

    Date2009.12.31 Category마이그레이션 By웁쓰 Views21924
    Read More
  6. glo 사용시 loaddb 주의 사항

    Date2009.12.31 Category기타 By웁쓰 Views18650
    Read More
  7. Integer 컬럼의 결과에 + or – 연산을 할 때 주의해야 할 점

    Date2009.12.31 Category질의작성 By웁쓰 Views13493
    Read More
  8. EVALUATE method 수행시 주의해야 할 점

    Date2009.12.31 Category기타 By웁쓰 Views12875
    Read More
  9. CUBRID설치 후 default설정 상태에서 Query Plan보기(CSQL모드)

    Date2009.12.31 Category질의작성 Bycubebridge Views16507
    Read More
  10. CUBRID Database page크기 확인 방법

    Date2009.12.31 Category운영관리 Byjanus Views16017
    Read More
  11. php에서 serialize/unserialize 사용 시 주의할 점

    Date2009.12.29 Category응용개발 By시난 Views31628
    Read More
  12. 쿼리로 인덱스 정보 확인하기

    Date2009.12.29 Category질의작성 By시난 Views24640
    Read More
  13. 쿼리로 테이블이 존재하는지 확인하기

    Date2009.12.28 Category질의작성 By시난 Views23521
    Read More
  14. CUBRID는 MySQL의 varchar(255)와 동일한 길이가 아닌가요?

    Date2009.12.28 Category마이그레이션 By손승일 Views27790
    Read More
  15. CUBRID AUTO_INCREMENT 컬럼 MySQL LAST_INSERT_ID() 대체 방법

    Date2009.12.22 Category응용개발 By손승일 Views33235
    Read More
  16. CUBRID Manager의 백업 자동화를 이용하여 요일 별로 백업을 하는 방법.

    Date2009.12.16 Category운영관리 Byseongjoon Views15668
    Read More
  17. CUBRID의 날짜형 타입을 java의 날짜형 타입에 할당할 때의 값 비교.

    Date2009.12.16 Category응용개발 Byseongjoon Views20420
    Read More
  18. CUBRID Manager에서 날짜타입이 있는 excel 파일 올릴때 주의할점.

    Date2009.12.16 CategoryCUBRID 매니저 Byseongjoon Views16933
    Read More
  19. 자동 백업, 매니져 관리자 암호 등의 설정에 대하여 CUBRID 배포판을 만들어 동일하게 배포하고자 할때

    Date2009.12.16 Category운영관리 By남재우 Views12829
    Read More
  20. CUBRID에서 systimestamp, sysdatetime default값에 대한 정의

    Date2009.12.16 Category응용개발 Bycubebridge Views28265
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 14 Next
/ 14

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales