This repository was archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathmongo.tutorial.connecting.html
57 lines (54 loc) · 3.42 KB
/
mongo.tutorial.connecting.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Making a Connection</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />
</head>
<body class="docs"><div class="navbar navbar-fixed-top">
<div class="navbar-inner clearfix">
<ul class="nav" style="width: 100%">
<li style="float: left;"><a href="mongo.tutorial.html">« Tutorial</a></li>
<li style="float: right;"><a href="mongo.tutorial.selectdb.html">Getting a Database »</a></li>
</ul>
</div>
</div>
<div id="breadcrumbs" class="clearfix">
<ul class="breadcrumbs-container">
<li><a href="index.html">PHP Manual</a></li>
<li><a href="mongo.tutorial.html">Tutorial</a></li>
<li>Making a Connection</li>
</ul>
</div>
<div id="layout">
<div id="layout-content"><div id="mongo.tutorial.connecting" class="section">
<h2 class="title">Making a Connection</h2>
<p class="para">
To connect to the database server, use one of the following:
</p>
<div class="example" id="mongo.tutorial.connecting-example">
<div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$connection </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(); </span><span style="color: #FF8000">// connects to localhost:27017<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">( </span><span style="color: #DD0000">"mongodb://example.com" </span><span style="color: #007700">); </span><span style="color: #FF8000">// connect to a remote host (default port: 27017)<br /></span><span style="color: #0000BB">$connection </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">( </span><span style="color: #DD0000">"mongodb://example.com:65432" </span><span style="color: #007700">); </span><span style="color: #FF8000">// connect to a remote host at a given port<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div>
<p class="para">
You do not have to explicitly disconnect from the database. The driver uses
persistent connections and will re-use already established connections.
</p>
<div class="section" id="mongo.tutorial.connecting.seealso">
<h2 class="title">See Also</h2>
<p class="para">
The chapter on <a href="mongo.connecting.html" class="link">connecting</a>
covers different types of connections.
</p>
<p class="para">
The API documentation on the <a href="class.mongoclient.html" class="classname">MongoClient</a> class and
<span class="function"><a href="mongoclient.construct.html" class="function">MongoClient::__construct()</a></span> give a comprehensive look at
all possible options with a number of examples.
</p>
</div>
</div></div></div></body></html>