Connect Azure's Documentdb PaaS via PHP's MongoDB driver

Source: Internet
Author: User
Tags install php install openssl mongodb driver php mongodb documentdb

Azure's Documentdb is a nosql type of database. It can also be compatible with today's popular MongoDB, with MongoDB's driver directly connected to Azure's ducumentdb.

Currently, DOCUMENTDB is officially commercially available on Azure, and the MongoDB-compatible version is still in the preview phase.

This article will show you how to create and connect documentdb through the driver of the PHP MongoDB.

Create a documentdb on the Azure management interface:

1 click the "+" sign in the upper-left corner of the portal, then enter DOCUMENTDB, return;

2 Select Ducumentdb-protocol Support for MongoDB (preview);

The option to accept preview appears in the middle, as accepted.

3 Click Create after the following dialog box appears, fill in the content as required;

4 minutes later you can see that the created Documentdb is online;

5 Creating DB and collection;

Click on the Created Documentdb and select Add Database in the overview;

Enter database's name;

Once the creation is successful, click this database;

After entering the database, click Add Collection;

In the dialog box that appears, type:

According to their own needs, select the corresponding performance services.

In a few seconds, collection was created.

6 record link string, in Documentdb there is an option called connection string, click, and Copy connection string:

Two install PHP MONGO on CentOS driver

1 creating repo for Epel and MONGO

Under/ETC/YUM.REPOS.D, add two files:

baseurl=$basearch enabled=1 gpgcheck=0
name=MongoDB 2.6 Repository
baseurl= gpgcheck=0 enabled=1

2 Yum Install the appropriate software:

yum install httpd -y
yum install php -y
yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath libmcrypt -y
yum install openssl-devel -y
yum install -y mongodb-org
yum install php-pecl-mongo

Php-pecl-mongo can also be installed by hand:

Download MongoDB Extensions

wget tar vxf mongodb-1.1.8.tgz mv mongodb-1.1.8 /usr/local/php-mongodb
cd /usr/local/php-mongodb/ ./configure --with-php-config=/usr/bin/php-config
Make && make install echo ‘extension =‘ > /etc/php.d/mongodb.ini

However, this installation requires attention to the compatibility of each version.

3 establishing a connection to Documentdb in PHP

Create index.php in/var/www/html

<?php //phpinfo(); $mongo = new mongo(‘mongodb://‘);
  echo "<br>";
  $mongodb = $mongo->mydb;
  echo "<br>";
  $collection = $mongodb->selectCollection(‘stu‘);
  for ($i=0; $i<=200; $i++){
    $array= array(‘_id‘=>$i+1,‘sn‘=>$i+1,‘name‘=>‘zhang san‘+$i,‘gender‘=>‘male‘,‘age‘=>8);
    $collection->insert($array); }
  echo "<br>";
  echo ‘count:‘ .$collection->count()."<br>"; ?>

Browse through a browser and see the following:

Indicates that the data has been inserted successfully.

Connect Azure's Documentdb PaaS via PHP's MongoDB driver

Related Article

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: 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.