Fraud Blocker
  • Solution
    • Solution
      • Enteros – SaaS Database Solution
      • Enteros – Expert Services
    • Use Cases
      • DevOps
      • Monitoring Business Performance
      • IT Production Operations
      • Cloud Migration and Scaling
      • Continuous Delivery
      • NoSQL / MongoDB / Cassandra
    • Industries
      • Insurance
      • Social Media & Entertainment
      • Government
      • Financial Services
      • Healthcare
      • Retail
      • Telecom
    • Roles
      • IT Production Operations
      • CIO
      • Engineering Manager
      • CFO
  • Product
    • UpBeat
      • Database Performance Management SaaS
    • UpBeat Platform
      • Cloud Cost Waste Analyzer (vCore & Credit Optimization)
      • AiOps DB Analytical Engine for Anomaly and Root Causes Detection
      • Deep Workload Diagnostics for Oracle Systems
      • Remediation Engine for Oracle Infrastractures
      • UpBeat Labs
    • DPMDPM is an innovative platform for IT production database performance management. The first of its kind, DPM provides decision support for each stage of the performance problem lifecycle
      • Learn more
  • Company
    •  About
      • Overview
      • Contact Us
      • Support
      • Partners
      • Careers
      • News
      • Blog
      • Management
    • Feature articleNPMD solutions play a key role in helping IT ops support increasingly complex technologies and services with network visibility, detection of performance issues and root cause analysis
      • Read more
    •  
  • Search
  • See Demo
  • Contact
(408) 824-1292

MongoDB PHP

See Live Demo Start Free Trial

Preamble

​​

MongoDB PHP: The database will receive a data stream from an external application or return this data back to it.

Therefore, we will need to organize work between MongoDB and an application written in one of the programming languages. PHP has been chosen as one of the most common programming languages, by the example of which we will consider such interaction.

Installing a driver for PHP

Read more"Indian Country" highlights Enteros and its database performance management platform *

Install the driver for the PHP language. The driver itself can be downloaded directly from the Github project page: github.com/mongodb/mongo-php-driver.

After loading the driver and unpacking its package on Unix systems, you should enter the following commands:

phpize
./configure
make
sudo make install

And then add the next line to the php.ini file:

extension=mongo.so

Read moreOracle AWR data storage and collection frequency optimization.

So, let’s download and unpack this archive package. It will contain drivers for possible versions of PHP. We need to select the one that corresponds to your version of PHP and put the corresponding driver file in the PHP/ext directory where all the extensions for PHP are stored.

Then you need to make a change to the php.ini file by adding the following line to the section where the extensions are connected:

extension=php_mongo-[version].dll

For example, in my case with the PHP 5.4 Tread Safe version I added the file php_mongo-1.4.5-5.4-vc9.dll to the PHP/ext directory. So I add extension=php_mongo-1.4.5-5.4-vc9.dll to php.ini.

Read moreMongoDB profiler and database performance problem diagnosis and identification

Then we reload the webserver and test it. To test the mongodb driver connection, you can use the standard phpinfo() function which outputs all PHP information to the webserver. In our case it should output the following:

Installing a driver for MongoBD PHP

 

Connecting to MongoDB from PHP

By connecting the driver to PHP, we can now connect to the database and interact with it from PHP code.

To establish a connection from the database, just write one line in the code:

$connection = new Mongo();

In this case, we connect to a server running on the localhost on standard port 27017. However, we can also connect to an external server:

$connection = new Mongo("somesite.com");

Here we are talking about connecting to a MongoDB server running on somesite.com and also on port 27017. If the port is different then we can also specify it:

$connection = new Mongo("somesite.com:888");

Once the database work is complete, we can close the connection using the close method:

$connection->close();

Document creation in PHP

Earlier we saw that a document in mongodb actually represents an object in a format similar to JSON. It can store keys with which certain values are mapped. The values themselves can also represent complex objects from keys and values. So, we created a document that represents an individual person:

steve = ({
"name": "Steve",
"age": 25,
"languages": ["engish", "french"],
company: {
"name": "Apple",
"year": 1976
}
})

Let’s create a similar document in PHP. To do this we will use associative arrays:

$steve = array(
"name" => "Steve",
"age" => 25,
"languages"=> array("engish", "french"),
"company" => array(
"name" => "Apple",
"year" => 1976
)
)

MongoDB PHP Tutorial Driver and PHP Library Set Up

 

About Enteros

IT organizations routinely spend days and weeks troubleshooting production database performance issues across multitudes of critical business systems. Fast and reliable resolution of database performance problems by Enteros enables businesses to generate and save millions of direct revenue, minimize waste of employees’ productivity, reduce the number of licenses, servers, and cloud resources and maximize the productivity of the application, database, and IT operations teams.

The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.

Are you interested in writing for Enteros’ Blog? Please send us a pitch!

 


RELATED POSTS

How Predictive Database Analytics Helps Optimize Cloud Resource Utilization

  • 23 June 2026
  • Database Performance Management

    As enterprises continue migrating workloads to the cloud, optimizing resource utilization has become a critical business priority. Cloud infrastructure offers scalability, flexibility, and operational agility, but it also introduces new cost and performance challenges. Without proper visibility into workload behavior, organizations often struggle to balance application performance with infrastructure efficiency. At the center of this … Continue reading “How Predictive Database Analytics Helps Optimize Cloud Resource Utilization”

    Continue Reading

    Why Proactive SQL Performance Monitoring Is Essential for Enterprise Growth

    • Database Performance Management

      In today’s digital economy, enterprise growth depends heavily on application speed, scalability, and reliability. As businesses expand their digital services, customer interactions, transactions, analytics, and operational workloads grow exponentially. Behind nearly every business-critical application lies SQL-driven databases that process and manage massive amounts of structured data in real time. From financial transactions and e-commerce purchases … Continue reading “Why Proactive SQL Performance Monitoring Is Essential for Enterprise Growth”

      Continue Reading

      How to Enable Data-Driven Media Growth with Enteros Cost Attribution and Software Management

      • 22 June 2026
      • Software Engineering

        Introduction The media industry is experiencing one of the most significant transformations in its history. Streaming services, digital publishing platforms, online advertising ecosystems, video-on-demand applications, and content distribution networks have fundamentally changed how audiences consume content. Modern media organizations now operate highly complex digital ecosystems that support: Streaming platforms Digital publishing systems Video content delivery … Continue reading “How to Enable Data-Driven Media Growth with Enteros Cost Attribution and Software Management”

        Continue Reading

        How to Enable Intelligent Wealth Management Operations with Enteros Database Software, AIOps Platform, and Gen AI

        • Database Performance Management

          Introduction The wealth management industry is undergoing a major transformation. As investors demand personalized financial services, real-time portfolio visibility, and digital-first experiences, wealth management firms are increasingly relying on technology to drive operational efficiency, improve client engagement, and accelerate business growth. Modern wealth management organizations now support: Portfolio management platforms Wealth advisory applications Digital client … Continue reading “How to Enable Intelligent Wealth Management Operations with Enteros Database Software, AIOps Platform, and Gen AI”

          Continue Reading

          Company

          • Production Database Performance Management
          • Enteros Professional Expert Services
          • NoSQL
          • Contact Us

          Solutions

          • DevOps
          • IT Production Operations
          • CFO: Maximize Financial Efficiency with Augmented FinOps
          • Engineering Manager
          • Retail

          UpBeat SaaS

          • Performance Explorer-i – Oracle Database Performance Management
          • High Load Capture – High Precision Database Performance Management
          • DBAct
          • Grid2Go – Advanced Database Analysis
          • Load2Test for Databases

          Resources

          • Verticals
          • Case Studies
          • UpBeat Access
          • UpBeat Documentation
          • Privacy Policy
          • Terms of Service

          Connect with Us

          Copyright © 2026 | Enteros, Inc. All Rights Reserved

          🎉 Thank you for subscribing!

          You're now on the list for database FinOps strategies and performance insights.