|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
use MongoDB\Model\CollectionInfo; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Instances of this class are used to interact with a database. |
|
20
|
|
|
* @link http://www.php.net/manual/en/class.mongodb.php |
|
21
|
|
|
*/ |
|
22
|
|
|
class MongoDB |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
const PROFILING_OFF = 0; |
|
25
|
|
|
const PROFILING_SLOW = 1; |
|
26
|
|
|
const PROFILING_ON = 2; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var int |
|
30
|
|
|
*/ |
|
31
|
|
|
public $w = 1; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var int |
|
35
|
|
|
*/ |
|
36
|
|
|
public $wtimeout = 10000; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var \MongoDB\Database |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $db; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Creates a new database |
|
45
|
|
|
* |
|
46
|
|
|
* This method is not meant to be called directly. The preferred way to create an instance of MongoDB is through {@see Mongo::__get()} or {@see Mongo::selectDB()}. |
|
47
|
|
|
* @link http://www.php.net/manual/en/mongodb.construct.php |
|
48
|
|
|
* @param MongoClient $conn Database connection. |
|
49
|
|
|
* @param string $name Database name. |
|
50
|
|
|
* @throws Exception |
|
51
|
|
|
* @return MongoDB Returns the database. |
|
|
|
|
|
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct($conn, $name) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->connection = $conn; |
|
|
|
|
|
|
56
|
|
|
$this->name = $name; |
|
|
|
|
|
|
57
|
|
|
$this->db = $this->connection->getClient()->selectDatabase($name); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return \MongoDB\Database |
|
62
|
|
|
* @internal |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getDb() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->db; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* The name of this database |
|
71
|
|
|
* @link http://www.php.net/manual/en/mongodb.--tostring.php |
|
72
|
|
|
* @return string Returns this database's name. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function __toString() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->name; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* (PECL mongo >= 1.0.2)<br/> |
|
81
|
|
|
* Gets a collection |
|
82
|
|
|
* @link http://www.php.net/manual/en/mongodb.get.php |
|
83
|
|
|
* @param string $name The name of the collection. |
|
84
|
|
|
* @return MongoCollection |
|
85
|
|
|
*/ |
|
86
|
|
|
public function __get($name) |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->selectCollection($name); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* (PECL mongo >= 1.3.0)<br/> |
|
93
|
|
|
* @link http://www.php.net/manual/en/mongodb.getcollectionnames.php |
|
94
|
|
|
* Get all collections from this database |
|
95
|
|
|
* @return array Returns the names of the all the collections in the database as an |
|
96
|
|
|
* {@link http://www.php.net/manual/en/language.types.array.php array}. |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getCollectionNames(array $options = []) |
|
99
|
|
|
{ |
|
100
|
|
|
if (is_bool($options)) { |
|
101
|
|
|
$options = ['includeSystemCollections' => $options]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$collections = $this->db->listCollections($options); |
|
105
|
|
|
|
|
106
|
|
|
$getCollectionName = function (CollectionInfo $collectionInfo) { |
|
107
|
|
|
return $collectionInfo->getName(); |
|
108
|
|
|
}; |
|
109
|
|
|
|
|
110
|
|
|
return array_map($getCollectionName, (array) $collections); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return MongoClient |
|
115
|
|
|
* @internal This method is not part of the ext-mongo API |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getConnection() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->connection; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
124
|
|
|
* Fetches toolkit for dealing with files stored in this database |
|
125
|
|
|
* @link http://www.php.net/manual/en/mongodb.getgridfs.php |
|
126
|
|
|
* @param string $prefix [optional] The prefix for the files and chunks collections. |
|
127
|
|
|
* @return MongoGridFS Returns a new gridfs object for this database. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getGridFS($prefix = "fs") |
|
130
|
|
|
{ |
|
131
|
|
|
return new \MongoGridFS($this, $prefix, $prefix); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
136
|
|
|
* Gets this database's profiling level |
|
137
|
|
|
* @link http://www.php.net/manual/en/mongodb.getprofilinglevel.php |
|
138
|
|
|
* @return int Returns the profiling level. |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getProfilingLevel() |
|
141
|
|
|
{ |
|
142
|
|
|
return static::PROFILING_OFF; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* (PECL mongo >= 1.1.0)<br/> |
|
147
|
|
|
* Get slaveOkay setting for this database |
|
148
|
|
|
* @link http://www.php.net/manual/en/mongodb.getslaveokay.php |
|
149
|
|
|
* @return bool Returns the value of slaveOkay for this instance. |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getSlaveOkay() |
|
152
|
|
|
{ |
|
153
|
|
|
return false; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
158
|
|
|
* Sets this database's profiling level |
|
159
|
|
|
* @link http://www.php.net/manual/en/mongodb.setprofilinglevel.php |
|
160
|
|
|
* @param int $level Profiling level. |
|
161
|
|
|
* @return int Returns the previous profiling level. |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setProfilingLevel($level) |
|
|
|
|
|
|
164
|
|
|
{ |
|
165
|
|
|
return static::PROFILING_OFF; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
170
|
|
|
* Drops this database |
|
171
|
|
|
* @link http://www.php.net/manual/en/mongodb.drop.php |
|
172
|
|
|
* @return array Returns the database response. |
|
173
|
|
|
*/ |
|
174
|
|
|
public function drop() |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->db->drop(); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Repairs and compacts this database |
|
181
|
|
|
* @link http://www.php.net/manual/en/mongodb.repair.php |
|
182
|
|
|
* @param bool $preserve_cloned_files [optional] <p>If cloned files should be kept if the repair fails.</p> |
|
183
|
|
|
* @param bool $backup_original_files [optional] <p>If original files should be backed up.</p> |
|
184
|
|
|
* @return array <p>Returns db response.</p> |
|
185
|
|
|
*/ |
|
186
|
|
|
public function repair($preserve_cloned_files = FALSE, $backup_original_files = FALSE) |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
return []; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
193
|
|
|
* Gets a collection |
|
194
|
|
|
* @link http://www.php.net/manual/en/mongodb.selectcollection.php |
|
195
|
|
|
* @param string $name <b>The collection name.</b> |
|
196
|
|
|
* @throws Exception if the collection name is invalid. |
|
197
|
|
|
* @return MongoCollection <p> |
|
198
|
|
|
* Returns a new collection object. |
|
199
|
|
|
* </p> |
|
200
|
|
|
*/ |
|
201
|
|
|
public function selectCollection($name) |
|
202
|
|
|
{ |
|
203
|
|
|
return new MongoCollection($this, $name); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* (PECL mongo >= 1.1.0)<br/> |
|
208
|
|
|
* Change slaveOkay setting for this database |
|
209
|
|
|
* @link http://php.net/manual/en/mongodb.setslaveokay.php |
|
210
|
|
|
* @param bool $ok [optional] <p> |
|
211
|
|
|
* If reads should be sent to secondary members of a replica set for all |
|
212
|
|
|
* possible queries using this {@link http://www.php.net/manual/en/class.mongodb.php MongoDB} instance. |
|
213
|
|
|
* </p> |
|
214
|
|
|
* @return bool Returns the former value of slaveOkay for this instance. |
|
215
|
|
|
*/ |
|
216
|
|
|
public function setSlaveOkay ($ok = true) |
|
|
|
|
|
|
217
|
|
|
{ |
|
218
|
|
|
return false; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Creates a collection |
|
223
|
|
|
* @link http://www.php.net/manual/en/mongodb.createcollection.php |
|
224
|
|
|
* @param string $name The name of the collection. |
|
225
|
|
|
* @param array $options [optional] <p> |
|
226
|
|
|
* <p> |
|
227
|
|
|
* An array containing options for the collections. Each option is its own |
|
228
|
|
|
* element in the options array, with the option name listed below being |
|
229
|
|
|
* the key of the element. The supported options depend on the MongoDB |
|
230
|
|
|
* server version. At the moment, the following options are supported: |
|
231
|
|
|
* </p> |
|
232
|
|
|
* <p> |
|
233
|
|
|
* <b>capped</b> |
|
234
|
|
|
* <p> |
|
235
|
|
|
* If the collection should be a fixed size. |
|
236
|
|
|
* </p> |
|
237
|
|
|
* </p> |
|
238
|
|
|
* <p> |
|
239
|
|
|
* <b>size</b> |
|
240
|
|
|
* <p> |
|
241
|
|
|
* If the collection is fixed size, its size in bytes.</p></p> |
|
242
|
|
|
* <p><b>max</b> |
|
243
|
|
|
* <p>If the collection is fixed size, the maximum number of elements to store in the collection.</p></p> |
|
244
|
|
|
* <i>autoIndexId</i> |
|
245
|
|
|
* |
|
246
|
|
|
* <p> |
|
247
|
|
|
* If capped is <b>TRUE</b> you can specify <b>FALSE</b> to disable the |
|
248
|
|
|
* automatic index created on the <em>_id</em> field. |
|
249
|
|
|
* Before MongoDB 2.2, the default value for |
|
250
|
|
|
* <em>autoIndexId</em> was <b>FALSE</b>. |
|
251
|
|
|
* </p> |
|
252
|
|
|
* </p> |
|
253
|
|
|
* @return MongoCollection <p>Returns a collection object representing the new collection.</p> |
|
254
|
|
|
*/ |
|
255
|
|
|
public function createCollection($name, $options) |
|
256
|
|
|
{ |
|
257
|
|
|
$this->db->createCollection($name, $options); |
|
258
|
|
|
return $this->selectCollection($name); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
263
|
|
|
* @deprecated Use MongoCollection::drop() instead. |
|
264
|
|
|
* Drops a collection |
|
265
|
|
|
* @link http://www.php.net/manual/en/mongodb.dropcollection.php |
|
266
|
|
|
* @param MongoCollection|string $coll MongoCollection or name of collection to drop. |
|
267
|
|
|
* @return array Returns the database response. |
|
268
|
|
|
*/ |
|
269
|
|
|
public function dropCollection($coll) |
|
270
|
|
|
{ |
|
271
|
|
|
return $this->db->dropCollection((string) $coll); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
276
|
|
|
* Get a list of collections in this database |
|
277
|
|
|
* @link http://www.php.net/manual/en/mongodb.listcollections.php |
|
278
|
|
|
* @param bool $includeSystemCollections [optional] <p>Include system collections.</p> |
|
|
|
|
|
|
279
|
|
|
* @return array Returns a list of MongoCollections. |
|
280
|
|
|
*/ |
|
281
|
|
|
public function listCollections(array $options = []) |
|
282
|
|
|
{ |
|
283
|
|
|
return array_map([$this, 'selectCollection'], $this->getCollectionNames($options)); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
288
|
|
|
* Creates a database reference |
|
289
|
|
|
* @link http://www.php.net/manual/en/mongodb.createdbref.php |
|
290
|
|
|
* @param string $collection The collection to which the database reference will point. |
|
291
|
|
|
* @param mixed $document_or_id <p> |
|
292
|
|
|
* If an array or object is given, its <em>_id</em> field will be |
|
293
|
|
|
* used as the reference ID. If a {@see MongoId} or scalar |
|
294
|
|
|
* is given, it will be used as the reference ID. |
|
295
|
|
|
* </p> |
|
296
|
|
|
* @return array <p>Returns a database reference array.</p> |
|
297
|
|
|
* <p> |
|
298
|
|
|
* If an array without an <em>_id</em> field was provided as the |
|
299
|
|
|
* <em>document_or_id</em> parameter, <b>NULL</b> will be returned. |
|
300
|
|
|
* </p> |
|
301
|
|
|
*/ |
|
302
|
|
|
public function createDBRef($collection, $document_or_id) |
|
303
|
|
|
{ |
|
304
|
|
|
if (is_object($document_or_id)) { |
|
305
|
|
|
$id = isset($document_or_id->_id) ? $document_or_id->_id : null; |
|
306
|
|
|
// $id = $document_or_id->_id ?? null; |
|
|
|
|
|
|
307
|
|
|
} elseif (is_array($document_or_id)) { |
|
308
|
|
|
if (! isset($document_or_id['_id'])) { |
|
309
|
|
|
return null; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
$id = $document_or_id['_id']; |
|
313
|
|
|
} else { |
|
314
|
|
|
$id = $document_or_id; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
return [ |
|
318
|
|
|
'$ref' => $collection, |
|
319
|
|
|
'$id' => $id, |
|
320
|
|
|
'$db' => $this->name, |
|
321
|
|
|
]; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* (PECL mongo >= 0.9.0)<br/> |
|
327
|
|
|
* Fetches the document pointed to by a database reference |
|
328
|
|
|
* @link http://www.php.net/manual/en/mongodb.getdbref.php |
|
329
|
|
|
* @param array $ref A database reference. |
|
330
|
|
|
* @return array Returns the document pointed to by the reference. |
|
331
|
|
|
*/ |
|
332
|
|
|
public function getDBRef(array $ref) |
|
|
|
|
|
|
333
|
|
|
{ |
|
334
|
|
|
$this->notImplemented(); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* (PECL mongo >= 1.5.0)<br/> |
|
339
|
|
|
* Get the write concern for this database |
|
340
|
|
|
* @link http://php.net/manual/en/mongodb.getwriteconcern.php |
|
341
|
|
|
* @return array <p>This function returns an array describing the write concern. |
|
342
|
|
|
* The array contains the values w for an integer acknowledgement level or string mode, |
|
343
|
|
|
* and wtimeout denoting the maximum number of milliseconds to wait for the server to satisfy the write concern.</p> |
|
344
|
|
|
*/ |
|
345
|
|
|
public function getWriteConcern() |
|
346
|
|
|
{ |
|
347
|
|
|
$this->notImplemented(); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* (PECL mongo >= 0.9.3)<br/> |
|
352
|
|
|
* Runs JavaScript code on the database server. |
|
353
|
|
|
* @link http://www.php.net/manual/en/mongodb.execute.php |
|
354
|
|
|
* @param MongoCode|string $code Code to execute. |
|
355
|
|
|
* @param array $args [optional] Arguments to be passed to code. |
|
356
|
|
|
* @return array Returns the result of the evaluation. |
|
357
|
|
|
*/ |
|
358
|
|
|
public function execute($code, array $args = array()) |
|
|
|
|
|
|
359
|
|
|
{ |
|
360
|
|
|
$this->notImplemented(); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Execute a database command |
|
365
|
|
|
* @link http://www.php.net/manual/en/mongodb.command.php |
|
366
|
|
|
* @param array $data The query to send. |
|
367
|
|
|
* @param array() $options [optional] <p> |
|
|
|
|
|
|
368
|
|
|
* This parameter is an associative array of the form |
|
369
|
|
|
* <em>array("optionname" => <boolean>, ...)</em>. Currently |
|
370
|
|
|
* supported options are: |
|
371
|
|
|
* </p><ul> |
|
372
|
|
|
* <li><p><em>"timeout"</em></p><p>Deprecated alias for <em>"socketTimeoutMS"</em>.</p></li> |
|
373
|
|
|
* </ul> |
|
374
|
|
|
* @return array Returns database response. |
|
375
|
|
|
* Every database response is always maximum one document, |
|
376
|
|
|
* which means that the result of a database command can never exceed 16MB. |
|
377
|
|
|
* The resulting document's structure depends on the command, |
|
378
|
|
|
* but most results will have the ok field to indicate success or failure and results containing an array of each of the resulting documents. |
|
379
|
|
|
*/ |
|
380
|
|
|
public function command(array $data, $options) |
|
|
|
|
|
|
381
|
|
|
{ |
|
382
|
|
|
$this->notImplemented(); |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* (PECL mongo >= 0.9.5)<br/> |
|
387
|
|
|
* Check if there was an error on the most recent db operation performed |
|
388
|
|
|
* @link http://www.php.net/manual/en/mongodb.lasterror.php |
|
389
|
|
|
* @return array Returns the error, if there was one. |
|
390
|
|
|
*/ |
|
391
|
|
|
public function lastError() |
|
392
|
|
|
{ |
|
393
|
|
|
$this->notImplemented(); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* (PECL mongo >= 0.9.5)<br/> |
|
398
|
|
|
* Checks for the last error thrown during a database operation |
|
399
|
|
|
* @link http://www.php.net/manual/en/mongodb.preverror.php |
|
400
|
|
|
* @return array Returns the error and the number of operations ago it occurred. |
|
401
|
|
|
*/ |
|
402
|
|
|
public function prevError() |
|
403
|
|
|
{ |
|
404
|
|
|
$this->notImplemented(); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* (PECL mongo >= 0.9.5)<br/> |
|
409
|
|
|
* Clears any flagged errors on the database |
|
410
|
|
|
* @link http://www.php.net/manual/en/mongodb.reseterror.php |
|
411
|
|
|
* @return array Returns the database response. |
|
412
|
|
|
*/ |
|
413
|
|
|
public function resetError() |
|
414
|
|
|
{ |
|
415
|
|
|
$this->notImplemented(); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* (PECL mongo >= 0.9.5)<br/> |
|
420
|
|
|
* Creates a database error |
|
421
|
|
|
* @link http://www.php.net/manual/en/mongodb.forceerror.php |
|
422
|
|
|
* @return boolean Returns the database response. |
|
423
|
|
|
*/ |
|
424
|
|
|
public function forceError() |
|
425
|
|
|
{ |
|
426
|
|
|
$this->notImplemented(); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
/** |
|
430
|
|
|
* (PECL mongo >= 1.0.1)<br/> |
|
431
|
|
|
* Log in to this database |
|
432
|
|
|
* @link http://www.php.net/manual/en/mongodb.authenticate.php |
|
433
|
|
|
* @param string $username The username. |
|
434
|
|
|
* @param string $password The password (in plaintext). |
|
435
|
|
|
* @return array <p>Returns database response. If the login was successful, it will return 1.</p> |
|
436
|
|
|
* <p> |
|
437
|
|
|
* <span style="color: #0000BB"><?php<br></span><span style="color: #007700">array(</span><span style="color: #DD0000">"ok" </span><span style="color: #007700">=> </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br></span><span style="color: #0000BB">?></span> |
|
438
|
|
|
* </span> |
|
439
|
|
|
* </code></div> |
|
440
|
|
|
* </div> |
|
441
|
|
|
* </p> |
|
442
|
|
|
* <p> If something went wrong, it will return </p> |
|
443
|
|
|
* <p> |
|
444
|
|
|
* <div class="example-contents"> |
|
445
|
|
|
* <div class="phpcode"><code><span style="color: #000000"> |
|
446
|
|
|
* <span style="color: #0000BB"><?php<br></span><span style="color: #007700">array(</span><span style="color: #DD0000">"ok" </span><span style="color: #007700">=> </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">"errmsg" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"auth fails"</span><span style="color: #007700">);<br></span><span style="color: #0000BB">?></span></p> |
|
447
|
|
|
* <p>("auth fails" could be another message, depending on database version and |
|
448
|
|
|
* what went wrong)</p> |
|
449
|
|
|
*/ |
|
450
|
|
|
public function authenticate($username, $password) |
|
|
|
|
|
|
451
|
|
|
{ |
|
452
|
|
|
$this->notImplemented(); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* (PECL mongo >= 1.3.0)<br/> |
|
457
|
|
|
* Get the read preference for this database |
|
458
|
|
|
* @link http://www.php.net/manual/en/mongodb.getreadpreference.php |
|
459
|
|
|
* @return array This function returns an array describing the read preference. The array contains the values type for the string read preference mode (corresponding to the MongoClient constants), and tagsets containing a list of all tag set criteria. If no tag sets were specified, tagsets will not be present in the array. |
|
460
|
|
|
*/ |
|
461
|
|
|
public function getReadPreference() |
|
462
|
|
|
{ |
|
463
|
|
|
$this->notImplemented(); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* (PECL mongo >= 1.3.0)<br/> |
|
468
|
|
|
* Set the read preference for this database |
|
469
|
|
|
* @link http://www.php.net/manual/en/mongodb.setreadpreference.php |
|
470
|
|
|
* @param string $read_preference <p>The read preference mode: <b>MongoClient::RP_PRIMARY</b>, <b>MongoClient::RP_PRIMARY_PREFERRED</b>, <b>MongoClient::RP_SECONDARY</b>, <b>MongoClient::RP_SECONDARY_PREFERRED</b>, or <b>MongoClient::RP_NEAREST</b>.</p> |
|
471
|
|
|
* @param array $tags [optional] <p>An array of zero or more tag sets, where each tag set is itself an array of criteria used to match tags on replica set members.</p> |
|
472
|
|
|
* @return boolean Returns <b>TRUE</b> on success, or <b>FALSE</b> otherwise. |
|
473
|
|
|
*/ |
|
474
|
|
|
public function setReadPreference($read_preference, array $tags) |
|
|
|
|
|
|
475
|
|
|
{ |
|
476
|
|
|
$this->notImplemented(); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
/** |
|
480
|
|
|
* (PECL mongo >= 1.5.0)<br/> |
|
481
|
|
|
* @link http://php.net/manual/en/mongodb.setwriteconcern.php |
|
482
|
|
|
* Set the write concern for this database |
|
483
|
|
|
* @param mixed $w <p>The write concern. This may be an integer denoting the number of servers required to acknowledge the write, or a string mode (e.g. "majority").</p> |
|
484
|
|
|
* @param int $wtimeout[optional] <p>The maximum number of milliseconds to wait for the server to satisfy the write concern.</p> |
|
|
|
|
|
|
485
|
|
|
* @return boolean Returns <b>TRUE</b> on success, or <b>FALSE</b> otherwise. |
|
486
|
|
|
*/ |
|
487
|
|
|
public function setWriteConcern($w, $wtimeout) |
|
|
|
|
|
|
488
|
|
|
{ |
|
489
|
|
|
$this->notImplemented(); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
protected function notImplemented() |
|
493
|
|
|
{ |
|
494
|
|
|
throw new \Exception('Not implemented'); |
|
495
|
|
|
} |
|
496
|
|
|
} |
|
497
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.