函式名:MongoDB\BSON\Document::fromBSON()
適用版本:PHP 5 >= 5.6.0, PHP 7, PECL mongodb >= 1.0.0
用法:MongoDB\BSON\Document::fromBSON() 函式將二進位制資料轉換為 MongoDB\BSON\Document 物件。
語法:public static MongoDB\BSON\Document MongoDB\BSON\Document::fromBSON(string $bson) : MongoDB\BSON\Document
引數:
- $bson:一個包含二進位制資料的字串。
返回值:
- 返回一個 MongoDB\BSON\Document 物件。
示例:
// 建立一個包含二進位制資料的字串
$bsonString = '...';
// 將二進位制資料轉換為 MongoDB\BSON\Document 物件
$document = MongoDB\BSON\Document::fromBSON($bsonString);
// 列印輸出 MongoDB\BSON\Document 物件
var_dump($document);
注意事項:
- 轉換的二進位制資料必須符合 BSON 格式,否則會丟擲異常。
- MongoDB\BSON\Document 物件是 MongoDB 驅動程式中常用的資料型別,用於表示 MongoDB 文件。