버클 리 DB 설치
Berkeley DB 는 많은 프로 그래 밍 언어 에 실 용적 인 api 인 터 페 이 스 를 제공 합 니 다.c,c+,자바,perl,tcl,python 과 phop 등 을 포함 합 니 다.데이터베이스 와 관련 된 모든 작업 은 Berkeley DB 함수 라 이브 러 리 에서 일괄 적 으로 수행 합 니 다.
공식 주 소 는:http://www.oracle.com/technology/products/berkeley-db/db/index.html
본 고 는 먼저 CentOS 에 Berkeley DB 데이터 베 이 스 를 설치 하 는 방법(다른 시스템 과 유사)을 설명 한다.
1.버클 리 DB 설치
# cd /usr/local/src
# wget http://download.oracle.com/berkeley-db/db-4.6.18.tar.gz
# tar -zxvf db-4.6.18.tar.gz
# cd db-4.6.18
# cd build_unix
Berkeley DB 는 기본적으로/usr/local/Berkeley DB.4.6 디 렉 터 리 에 설치 되 어 있 으 며,그 중 4.6 은 버 전 번호 이 며,설치 디 렉 터 리 를 설정 하기 위해–prefix 인 자 를 지정 할 수 있 습 니 다.
# ../dist/configure --prefix=/usr/local/berkeleydb --enable-cxx
그 중–enable-cxx 는 C++라 이브 러 리 를 컴 파일 해 야 Berkeley DB 데이터베이스 의 PHP 확장 pp 를 컴 파일 할 수 있 습 니 다.db4。
# make
# make install
# echo '/usr/local/berkeleydb/lib/' >> /etc/ld.so.conf
# ldconfig
이 두 문장의 역할 은 시스템 Berkeley DB 의 동적 링크 라 이브 러 리 가/usr/local/berkeley db/lib/디 렉 터 리 에 있 음 을 알 리 는 것 이다.
이로써 버클 리 DB 데이터 베 이 스 는 설치 가 완료 됐다.
2、Berkeley DB 를 설치 한 PHP 확장db 와 phpdba 두 확장 자 는 모두 Berkekey DB 를 지원 하지만 지원 에 한계 가 있 기 때문에 Berkeley DB 가 자체 적 으로 가지 고 있 는 pp 를 컴 파일 합 니 다.db4 확장 이 좋 습 니 다.
# cd /usr/local/src/db-4.6.18/php_db4/
# phpize
# ./configure --with-db4=/usr/local/berkeleydb/
# make
# make install
이로써 db4 는/usr/lib 64/php/modules/db4.so 디 렉 터 리 에 컴 파일 되 었 습 니 다(구체 적 으로 시스템 과 관련 이 있 습 니 다)
php.ini 파일 수정
추가:
extension=db4.so
WEB 서버 다시 시작(Apache 등)db4 확장 설치 도 완료 되 었 습 니 다.phop-m 를 실행 하면 db4 확장 이 불 러 온 것 을 볼 수 있 습 니 다.
말 그대로 Db4Env 는 데이터베이스 환경 설정,Db4 조작 데이터베이스,Db4Txn 은 사무 처리,Db4Cursor 는 커서 처리 에 사 용 됩 니 다.구체 적 인 사용 은 php 의 함수 참고:패키지 의 원본 코드 를 참고 할 수 있 습 니 다.
c 의 참고 함수:http://www.oracle.com/technology/documentation/berkeley-db/db/api_cxx/frame.html
/usr/local/src/db-4.6.18/php_db4/samples 디 렉 터 리 에 간단 한 예 2 개 를 제공 합 니 다 simplecounter.php 와 transactionalcounter.php。
simple_counter.php
<?php
// Create a new Db4 Instance
$db = new Db4();
// Open it outside a Db4Env environment with datafile/var/lib/db4
// and database name "test"
$db->open(null, "/var/tmp/db4", "test");
// Get the current value of "counter"
$counter = $db->get("counter");
print "Counter Value is $counter
";
// Increment $counter and put() it.
$db->put("counter", $counter+1);
// Sync to be certain, since we're leaving the handle open
$db->sync();
?>
transactional_counter.php
<?php
// Open a new Db4Env
$dbenv = new Db4Env();
$dbenv->set_data_dir("/var/tmp/dbhome");
$dbenv->open("/var/tmp/dbhome");
// Open a database in $dbenv. Note that even though
// we pass null in as the transaction, db4 forces this
// operation to be transactionally protected, so PHP
// will force auto-commit internally.
$db = new Db4($dbenv);
$db->open(null, 'a', 'foo');
$counter = $db->get("counter");
// Create a new transaction
$txn = $dbenv->txn_begin();
if($txn == false) {
print "txn_begin failed";
exit;
}
print "Current value of counter is $counter
";
// Increment and reset counter, protect it with $txn
$db->put("counter", $counter+1, $txn);
// Commit the transaction, otherwise the above put() will rollback.
$txn->commit();
// Sync for good measure
$db->sync();
// This isn't a real close, use _close() for that.
$db->close();
?>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.