update : 2015.11.03
php.shukuma.com검색:
|
Using the libraryAfter the initial set-up, we continue explaining how to get started with the MongoDB driver and library for HHVM to write our first project. PHP Library (PHPLIB)The last thing we still need to install to get started on the application itself, is the PHP library.
The library needs to be installed with Composer. In your project directory
( curl -sS https://getcomposer.org/installer -o installer.php hhvm installer.php rm installer.php This downloads and installs Composer. Wherever it says "Use it: php composer.phar", it of course means hhvm composer.phar. With Composer installed, we can now install the library: hhvm composer.phar require mongodb/mongodb It outputs something akin to: Using version ^0.2.0 for mongodb/mongodb ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) - Installing mongodb/mongodb (0.2.0) Downloading: 100% Writing lock file Generating autoload files
And it has created several files ( Using the LibraryComposer manages your dependencies, and will provide you with a loader that you include with the following at the start of your script:
<?php With this done, you can now use any of the functionality as described in the » documentation. If you are familiar with the old driver, it should look too much out of place. The only big difference is that the » Database class is only used for Database specific operations. The » CRUD operations on the » Collection class are also renamed for clarity, and to be in accordance with a new language-agnostic » specification. As an example, this is how you insert a document into the beers collection of the demo database:
<?php
Instead of the original document being modified to add the newly generated
After insertion, you can of course also query the data that you have just
inserted. For that, you use the
<?php
You might have noticed that instead of accessing the |