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. csql 데이터 입력방법

    Date2009.06.09 Category운영관리 By정만영 Views213308
    Read More
  2. CUBRID vs MySQL vs ORACLE SQL 타입별 비교

    Date2013.07.12 Category마이그레이션 By정만영 Views69160
    Read More
  3. weblogic 8.1 에 CUBRID Connection Pool, DataSource 설정 방법

    Date2009.07.01 Category응용개발 By웁쓰 Views66306
    Read More
  4. WHERE 조건에서 다중 컬럼 IN절 처리 최적화 방법 (cubrid + ibatis)

    Date2015.08.21 Category응용개발 By이상신 Views55134
    Read More
  5. Weblogic 10.0 사용시 JDK 1.5를 사용한 JDBC 드라이버 사용시 주의사항.

    Date2012.02.22 Category응용개발 Bycubebridge Views51957
    Read More
  6. 타 DBMS를 CUBRID로 마이그레이션 시 varchar,char 컬럼 사이즈 관련

    Date2010.07.01 Category마이그레이션 By손승일 Views38024
    Read More
  7. 데이터 존재하면 update, 존재하지 않으면 insert 방법(ON DUPLICATE KEY UPDATE)

    Date2010.08.11 Category질의작성 By손승일 Views37999
    Read More
  8. 예약어를 테이블명이나 컬럼명으로 사용시

    Date2008.11.21 Category질의작성 Byadmin Views37422
    Read More
  9. JDBC 사용시 SQL 로깅 - p6spy 사용

    Date2009.07.01 Category응용개발 By웁쓰 Views36001
    Read More
  10. 좀비 프로세스 일괄 삭제하기

    Date2009.12.12 Category기타 Byjanus Views34920
    Read More
  11. CUBRID AUTO_INCREMENT 컬럼 MySQL LAST_INSERT_ID() 대체 방법

    Date2009.12.22 Category응용개발 By손승일 Views33235
    Read More
  12. CUBRID에서의 BLOB/CLOB 사용시 백업 및 복구에 대한 주의 점

    Date2012.09.18 Category운영관리 Bycubebridge Views33157
    Read More
  13. MySQL의 limit 명령어 처리

    Date2008.11.21 Category마이그레이션 Byadmin Views32685
    Read More
  14. Java SP사용시 JNI_CreateJavaVM 에러메시지 해결 방법

    Date2009.07.15 CategoryCUBRID 매니저 Byseongjoon Views32043
    Read More
  15. php에서 serialize/unserialize 사용 시 주의할 점

    Date2009.12.29 Category응용개발 By시난 Views31628
    Read More
  16. CUBRID 사용시 방화벽 설정

    Date2008.11.21 Category운영관리 Byadmin Views30996
    Read More
  17. CUBRID 하위버젼에서 CUBRID2008로의 업그레이드 방법

    Date2008.12.06 Category마이그레이션 By남재우 Views30154
    Read More
  18. 큐브리드 사용포트 정리

    Date2009.06.19 Category운영관리 By정만영 Views29776
    Read More
  19. CUBRID DB 내의 auto_increment 값을 초기화 하자.

    Date2009.10.28 Category질의작성 By손승일 Views29732
    Read More
  20. CUBRID와 Oracle에서의 ''(공백)의 차이 비교

    Date2010.10.01 Category응용개발 Bycubebridge Views28583
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 14 Next
/ 14

Contact Cubrid

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