forked from mongodb/docs-ecosystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp-drivers.txt
More file actions
182 lines (127 loc) · 5.6 KB
/
php-drivers.txt
File metadata and controls
182 lines (127 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
.. _php-language-center:
==================
MongoDB PHP Driver
==================
.. facet::
:name: programming_language
:values: php
.. facet::
:name: genre
:values: tutorial
.. meta::
:description: Use the PHP driver and libraries to connect to MongoDB Atlas, Enterprise, and Community database deployments.
:keywords: code example
.. toctree::
:titlesonly:
Laravel MongoDB <https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current>
Symfony Integration </php-frameworks/symfony>
Drupal Integration </php-frameworks/drupal>
Libraries, Frameworks, & Tools </php-libraries>
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: twocols
Introduction
------------
Welcome to the documentation site for the official MongoDB PHP driver.
You can add the driver to your application to work with MongoDB in PHP.
The MongoDB PHP Driver consists of the following components:
- `Extension <https://php.net/mongodb>`__:
Provides a low-level API and mainly serves to integrate
the `libmongoc <https://mongoc.org/libmongoc/current/>`__ and
`libbson <https://mongoc.org/libbson/current/>`__ libraries with PHP.
- `Library <https://www.mongodb.com/docs/php-library/current>`__:
Provides a high-level API for working with MongoDB
databases consistent with other MongoDB language drivers.
While it is possible to use only the extension, we recommend
using the extension and the library together. To learn more about
the components of the PHP driver, see the :ref:`php-driver-arch` section
of this page.
View the following guides to learn more about the driver and access
tutorial content on setting up a runnable project:
- `Get Started with the PHP Library <https://www.mongodb.com/docs/php-library/current/get-started/>`__
- `Connect to MongoDB <https://www.mongodb.com/docs/php-library/current/connect/>`__
Reference
~~~~~~~~~
- :github:`Release Notes <mongodb/mongo-php-driver/releases>`
- :github:`Driver Source Code <mongodb/mongo-php-driver>`
.. _php-driver-arch:
Driver Architecture
-------------------
This section describes how the components of the PHP driver work together.
These components fit into the following general categories:
- High-Level API, which includes the library and other integrations
- Extension, which includes the extension that integrates the system libraries
- System, which includes the C Driver, BSON library, and encryption library
The following diagram illustrates the architecture of the PHP driver
components:
.. figure:: /figures/PHP_driver_architecture.svg
:alt: PHP driver component architecture
:figwidth: 600px
The PHP library provides an API that is consistent with the other
MongoDB drivers. The library is continually updated to meet cross-driver
specifications. You must add the library as a dependency to access
MongoDB in most PHP applications.
The extension is distributed by using `PECL
<https://www.php.net/manual/en/mongodb.installation.php>`__, and
connects PHP to the system libraries. The extension's public API
provides the following functionality:
- Connection management
- BSON encoding and decoding
- Object document serialization
- Command execution
- Cursor management
To learn more about the system libraries, see the `C Driver
<https://www.mongodb.com/docs/languages/c/c-driver/current/>`__ documentation.
Connect to a Compatible MongoDB Deployment
------------------------------------------
You can use the PHP driver to connect to deployments hosted in the
following environments:
.. include:: /includes/fact-environments.rst
Installation
------------
Make sure you have a recent version of PHP installed on your
system. See the `PHP manual <https://www.php.net/manual/en/install.php>`__
for download and installation instructions.
Install the PHP MongoDB Extension before you install the MongoDB PHP
Library. You can install the extension by using :github:`pie
</php/pie>` on the command line:
.. code-block:: sh
pie install mongodb/mongodb-extension
Then, install the PHP library by using `Composer
<https://getcomposer.org/>`__. Run the following command from your
project directory:
.. code-block:: sh
composer require mongodb/mongodb
After installation completes, ensure that your application includes
Composer's autoloader as shown in the following example:
.. code-block:: php
<?php
require_once __DIR__ . '/vendor/autoload.php';
The `PHP Library documentation
<https://www.mongodb.com/docs/php-library/current>`__ contains reference
materials and tutorials that demonstrate how to interact with your
MongoDB data.
Compatibility
-------------
Due to potential problems representing 64-bit integers on 32-bit platforms,
users are advised to use 64-bit environments. When using a 32-bit platform, be
aware that any 64-bit integer read from the database will be returned as a
`MongoDB\\BSON\\Int64 <https://www.php.net/manual/en/class.mongodb-bson-int64.php>`__
instance instead of a PHP integer type.
MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~
The following compatibility table specifies the recommended version or versions
of the PHP driver for use with a specific version of MongoDB.
The first column lists the driver version.
.. sharedinclude:: dbx/lifecycle-schedule-callout.rst
.. sharedinclude:: dbx/mongodb-compatibility-table-php.rst
Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~
The following compatibility table specifies the recommended version or versions
of the PHP driver for use with a specific version of PHP.
The first column lists the driver versions.
.. sharedinclude:: dbx/language-compatibility-table-php.rst
.. include:: /includes/about-driver-compatibility.rst
.. include:: /includes/help-links-php.rst