<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                有個composer包 composer require "mongodb/mongodb=^1.0.0@beta" https://github.com/mongodb/mongo-php-library laravel的包 composer require jenssegers/mongodb http://www.jianshu.com/p/841e05db7f97 https://laravel-china.org/articles/2560/using-mongodb-in-laravel # 連接 ~~~ $username='username'; $passwd='passwd'; $host='127.0.0.1'; $port='27017'; $dbb='dbname'; $mongodb = new MongoDB\Driver\Manager("mongodb://{$username}:{$passwd}@{$host}:$port/$dbb"); ~~~ 還有種 ~~~ $ip = "127.0.0.1"; $port = '27017'; $dns = 'mongodb://'.$ip.':'.$port; $manager = new \MongoClient($dns); var_dump($manager); ~~~ # 插入數據 將 name 為"菜鳥教程" 的數據插入到 test 數據庫的 runoob 集合中。 ~~~ <?php $bulk = new MongoDB\Driver\BulkWrite; $document = ['_id' => new MongoDB\BSON\ObjectID, 'name' => '菜鳥教程']; $_id= $bulk->insert($document); var_dump($_id); $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); $result = $manager->executeBulkWrite('test.runoob', $bulk, $writeConcern); ?> ~~~ # 讀取數據 這里我們將三個網址數據插入到 test 數據庫的 sites 集合,并讀取迭代出來: ~~~ <?php $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); // 插入數據 $bulk = new MongoDB\Driver\BulkWrite; $bulk->insert(['x' => 1, 'name'=>'菜鳥教程', 'url' => 'http://www.runoob.com']); $bulk->insert(['x' => 2, 'name'=>'Google', 'url' => 'http://www.google.com']); $bulk->insert(['x' => 3, 'name'=>'taobao', 'url' => 'http://www.taobao.com']); $manager->executeBulkWrite('test.sites', $bulk); $filter = ['x' => ['$gt' => 1]]; $options = [ 'projection' => ['_id' => 0], 'sort' => ['x' => -1], ]; // 查詢數據 $query = new MongoDB\Driver\Query($filter, $options); $cursor = $manager->executeQuery('test.sites', $query); foreach ($cursor as $document) { print_r($document); } ?> ~~~ 輸出結果為: ~~~ stdClass Object ( [x] => 3 [name] => taobao [url] => http://www.taobao.com ) stdClass Object ( [x] => 2 [name] => Google [url] => http://www.google.com ) ~~~ # 更新數據 接下來我們將更新 test 數據庫 sites 集合中 x 為 2 的數據: ~~~ <?php $bulk = new MongoDB\Driver\BulkWrite; $bulk->update( ['x' => 2], ['$set' => ['name' => '菜鳥工具', 'url' => 'tool.runoob.com']], ['multi' => false, 'upsert' => false] ); $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); ?> ~~~ 接下來我們使用 "db.sites.find()" 命令查看數據的變化,x 為 2 的數據已經變成了菜鳥工具: # 刪除數據 以下實例刪除了 x 為 1 和 x 為 2的數據,注意 limit 參數的區別: <?php $bulk = new MongoDB\Driver\BulkWrite; $bulk->delete(['x' => 1], ['limit' => 1]); // limit 為 1 時,刪除第一條匹配數據 $bulk->delete(['x' => 2], ['limit' => 0]); // limit 為 0 時,刪除所有匹配數據 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); ?>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看