CakePHP and MongoDB Integration Tutorial _php Tutorial

Source: Internet
Author: User
There is no MONGODB test environment can be installed on the local MongoDB service, here is MongoDB in Windows under the text installation tutorial.

PHP default does not open the MongoDB extension, you need to manually download the MONGO extension on the official website, find a suitable MONGO extension for your system, unzip it into the PHP environment specified in the EXT directory, and add in the php.ini file

Extension=php_mongo.dll

Restart Apache and other servers to take effect.

Download cakephp and MongoDB datasouce from GitHub and install it in the app/plugins/directory

PS: No git comrades do not worry, you can download directly

After the download is complete, you can configure MongoDB in database.php:

var $mongo = Array (
' DataSource ' = ' Mongodb.mongodbsource ',
' Database ' = ' Testmongo ',
' Host ' = ' localhost ',
' Port ' = 27017
);

You can create a model to use it in the controller:

mongb.php

Class Mondb extends Appmodel {
var $name = ' mondb ';
var $primaryKey = ' _id ';
var $useDbConfig = ' MONGO ';

function schema () {
$this->_schema = Array (
' _id ' = = Array (' type ' = ' = ' integer ', ' primary ' = = true, ' length ' = 40),
' a ' = = Array (' type ' = ' string '),
' b ' = = Array (' type ' = ' = ' integer '),
);
return $this->_schema;
}

}
?>

Then you can manipulate MongoDB in the controller:

function Mongo () {
$this-Loadmodel (' mondb ');
$res = Mondb, $this, Save (Array ("a" = "Test MongoDB", "B" =>time ()));
$res = Find (' All '), MONDB, $this
PR ($res);
Exit
}

http://www.bkjia.com/PHPjc/364753.html www.bkjia.com true http://www.bkjia.com/PHPjc/364753.html techarticle There is no MONGODB test environment can be installed on the local MongoDB service, here is MongoDB in Windows under the text installation tutorial. PHP default does not open the MongoDB extension, need to manually to the official website ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.