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 •

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
139 응용개발 오라클 to CUBRID로 마이그레이션 수행 시 주의사항 cubebridge 2012.11.12 16642
138 응용개발 PHP에 CUBRID 모듈 추가시 모듈이 로드되지 않는 문제에 대한 해결 방안 하나입니다 남재우 2010.07.01 16557
137 운영관리 브로커 상태를 확인할 때 status 의미 시난 2009.11.27 16552
136 CUBRID 매니저 테이블 명세서 한 시트로 합치기 file 성진 2015.12.24 16526
135 질의작성 CUBRID설치 후 default설정 상태에서 Query Plan보기(CSQL모드) cubebridge 2009.12.31 16507
134 운영관리 Window서버 cmd창에서 CUBRID 구동 후 cmd창을 닫을 시 DB서비스 중단 조치방법 cubebridge 2009.10.29 16464
133 운영관리 CUBRID 쿼리 수행 중단 시 주의 사항 cubebridge 2010.03.04 16423
132 CUBRID 매니저 CUBRID에서 OID 확인하는 방법 file seongjoon 2010.01.02 16308
131 기타 CUBRID의OLE DB 드라이버 설치 방법. file seongjoon 2009.08.24 16263
130 운영관리 CUBRID Database page크기 확인 방법 janus 2009.12.31 16017
129 운영관리 CUBRID 2008 삭제시 제어판에서 삭제되지 않을시 해결법 file seongjoon 2009.04.13 15892
128 운영관리 CUBRID제거 절차 janus 2009.12.12 15888
127 응용개발 jdbc에서 질의 플랜정보 보는 방법 손승일 2009.04.15 15840
126 운영관리 디비와 테이블 문자셋이 다른 경우 처리 방법 이용미 2015.06.03 15803
125 질의작성 CUBRID에서 응용프로그램 쿼리 binding 구문이 있을 경우 plan의 차이 cubebridge 2009.11.06 15700
124 운영관리 CUBRID Manager의 백업 자동화를 이용하여 요일 별로 백업을 하는 방법. file seongjoon 2009.12.16 15668
123 마이그레이션 CUBRID와 Oracle의 NULL과 '' (empty string)의 처리 차이점 1 권호일 2015.12.29 15424
122 질의작성 스키마에서 한글 사용하는 방법 file seongjoon 2009.04.14 15362
121 CUBRID 매니저 여러 버전의 CUBRID에 CUBRID Manager로 연결하는 방법 일동차렷? 2009.03.14 15355
120 CUBRID 매니저 CUBRID Manager에서 데이터 검색 결과를 파일로 내려받는 방법. file seongjoon 2010.02.09 15321
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