MongoDB PHP DriverMongoDB 的 PHP 驱动包

联合创作 · 2023-09-30 19:16

mongo-php-driver 是 MongoDB 御用的 PHP 驱动包。

示例代码:

<?php

// connect
$m = new Mongo();

// select a database
$db $m->comedy;

// select a collection (analogous to a relational database's table)
$collection $db->cartoons;

// add a record
$obj = array( "title" => "Calvin and Hobbes""author" => "Bill Watterson" );
$collection->insert($obj);

// add another record, with a different "shape"
$obj = array( "title" => "XKCD""online" => true );
$collection->insert($obj);

// find everything in the collection
$cursor $collection->find();

// iterate through the results
foreach ($cursor as $obj) {
    echo 
$obj["title"] . "\n";
}


?>

浏览 5
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报