Background Image
조회 수 31624 추천 수 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. CUBRID에서 euc-kr의 한글 데이터를 utf-8의 한글 데이터로 변경 시 주의할 점

    Date2010.04.01 Category응용개발 Bycubebridge Views22380
    Read More
  2. 패키지 형태로 생성된 JAVA class를 JAVA SP에서 사용하기

    Date2010.02.26 Category응용개발 By손승일 Views18371
    Read More
  3. CUBRID2008 Java Stored Procedure 등록 방법

    Date2010.02.24 Category응용개발 Bycubebridge Views19559
    Read More
  4. php에서 serialize/unserialize 사용 시 주의할 점

    Date2009.12.29 Category응용개발 By시난 Views31624
    Read More
  5. CUBRID AUTO_INCREMENT 컬럼 MySQL LAST_INSERT_ID() 대체 방법

    Date2009.12.22 Category응용개발 By손승일 Views33233
    Read More
  6. CUBRID의 날짜형 타입을 java의 날짜형 타입에 할당할 때의 값 비교.

    Date2009.12.16 Category응용개발 Byseongjoon Views20414
    Read More
  7. CUBRID에서 systimestamp, sysdatetime default값에 대한 정의

    Date2009.12.16 Category응용개발 Bycubebridge Views28250
    Read More
  8. JAVA SP를 통해 다른 데이터베이스 연결하는 경우 잊지 말자.

    Date2009.12.16 Category응용개발 By손승일 Views17975
    Read More
  9. CUBRID odbc 드라이버 설정방법.

    Date2009.12.10 Category응용개발 Byseongjoon Views20325
    Read More
  10. PHP에서 Prepared statement 사용시 NULL 값을 바인딩 하는 방법

    Date2009.11.27 Category응용개발 ByPrototype Views19719
    Read More
  11. 용량이 큰 데이터를 질의로 저장하는 방법

    Date2009.11.26 Category응용개발 By남재우 Views12116
    Read More
  12. 윈도우 환경에서 PHP 모듈 로드를 못 할 경우 해결법

    Date2009.11.26 Category응용개발 ByPrototype Views22261
    Read More
  13. CUBRID에서 제약조건(PK,FK,UNIQUE),index 설정 시 주의 사항

    Date2009.11.26 Category응용개발 Bycubebridge Views18884
    Read More
  14. MySQL의 Blob타입을 CUBRID로 변환하기

    Date2009.11.18 Category응용개발 Bycubebridge Views18848
    Read More
  15. CUBRID의 Statement pooling기능

    Date2009.11.06 Category응용개발 Bycubebridge Views16940
    Read More
  16. 그루비로 큐브리드 함수(or 프로시저) 만들기 by 행복개발자(cyberuls)

    Date2009.07.14 Category응용개발 By시난 Views18753
    Read More
  17. JDBC 커넥션 스트링에 UTF-8 명시하는법

    Date2009.07.03 Category응용개발 ByPrototype Views19016
    Read More
  18. weblogic 8.1 에 CUBRID Connection Pool, DataSource 설정 방법

    Date2009.07.01 Category응용개발 By웁쓰 Views66305
    Read More
  19. JDBC 사용시 SQL 로깅 - p6spy 사용

    Date2009.07.01 Category응용개발 By웁쓰 Views35985
    Read More
  20. PHP 프로그램을 작성할때 주의할 점

    Date2009.07.01 Category응용개발 ByPrototype Views13728
    Read More
Board Pagination Prev 1 2 3 Next
/ 3

Contact Cubrid

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