라이브러리
[PHP] MongoDBBSONDocument::fromBSON - BSON 문자열에서 새 문서 인스턴스 구성
MongoDBBSONDocument::fromBSON
`MongoDBBSONDocument::fromBSON`는 MongoDB의 BSON 문서를 PHP의 `MongoDBBSONDocument` 객체로 변환하는 메서드입니다. 이 메서드는 MongoDB의 BSON 문서를 PHP의 객체로 변환하여, PHP에서 쉽게 사용할 수 있도록 해줍니다.
 사용법
`MongoDBBSONDocument::fromBSON` 메서드는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
use MongoDBBSONDocument;
$bsonDocument = new Document([
    'name' => 'John Doe',
    'age' => 30,
    'address' => [
        'street' => '123 Main St',
        'city' => 'New York',
        'state' => 'NY',
        'zip' => '10001'
    ]
]);
$phpDocument = MongoDBBSONDocument::fromBSON($bsonDocument);
print_r($phpDocument);
 예제
이 예제에서는 MongoDB의 BSON 문서를 PHP의 `MongoDBBSONDocument` 객체로 변환하는 방법을 보여줍니다.
#hostingforum.kr
php
use MongoDBBSONDocument;
use MongoDBBSONUTCDateTime;
// MongoDB의 BSON 문서
$bsonDocument = new Document([
    'name' => 'John Doe',
    'age' => 30,
    'address' => [
        'street' => '123 Main St',
        'city' => 'New York',
        'state' => 'NY',
        'zip' => '10001'
    ],
    'created_at' => new UTCDateTime()
]);
// PHP의 MongoDBBSONDocument 객체로 변환
$phpDocument = MongoDBBSONDocument::fromBSON($bsonDocument);
// PHP의 MongoDBBSONDocument 객체를 사용하여 데이터를 출력
echo "이름: " . $phpDocument->name . "
";
echo "나이: " . $phpDocument->age . "
";
echo "주소: " . $phpDocument->address->street . ", " . $phpDocument->address->city . ", " . $phpDocument->address->state . " " . $phpDocument->address->zip . "
";
echo "생성일: " . $phpDocument->created_at->toDateTime()->format('Y-m-d H:i:s') . "
";
 결과
이 예제의 결과는 다음과 같습니다.
#hostingforum.kr
이름: John Doe
나이: 30
주소: 123 Main St, New York, NY 10001
생성일: 2023-02-13 14:30:00
 참고
* MongoDB의 BSON 문서는 PHP의 `MongoDBBSONDocument` 객체로 변환할 수 있습니다.
* `MongoDBBSONDocument::fromBSON` 메서드는 MongoDB의 BSON 문서를 PHP의 `MongoDBBSONDocument` 객체로 변환합니다.
* PHP의 `MongoDBBSONDocument` 객체는 MongoDB의 BSON 문서를 쉽게 사용할 수 있도록 해줍니다.
- 
                 
- 나우호스팅 @pcs8404
- 
            
                호스팅포럼 화이팅!
            		
댓글목록
등록된 댓글이 없습니다.