PHP Doku:: Creates a database reference - mongodb.createdbref.html

Verlauf / Chronik / History: (2) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenMongoDB Native DriverCore ClassesThe MongoDB classMongoDB::createDBRef

Ein Service von Reinhard Neidl - Webprogrammierung.

The MongoDB class

<<MongoDB::createCollection

MongoDB::drop>>

MongoDB::createDBRef

(PECL mongo >=0.9.0)

MongoDB::createDBRefCreates a database reference

Beschreibung

public array MongoDB::createDBRef ( string $collection , mixed $a )

This method is a flexible interface for creating database refrences (see MongoDBRef).

Parameter-Liste

collection

The collection to which the database reference will point.

a

Object or _id to which to create a reference. If an object or associative array is given, this will create a reference using the _id field.

Rückgabewerte

Returns a database reference array.

Beispiele

Beispiel #1 MongoDB::createDBRef() example

Example demonstrating how to programatically create a DB reference array from a document.

<?php

$articles 
$db->articles;

$article = array(
 
'title' => 'Test article',
 
'description' => 'Test article description'
);

$articles->insert($article);
$ref $db->createDBRef('articles'$article);

print_r($article);
print_r($ref);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

     Array
     (
         [title] => Test article
         [description] => Test article description
         [_id] => MongoId Object
             (
             )

     )
     Array
     (
         [$ref] => articles
         [$id] => MongoId Object
             (
             )

     )
     

Now the $ref can be stored on another document and retrieved later with MongoDB::getDBRef() or MongoCollection::getDBRef().

Beispiel #2 MongoDB::createDBRef() example

Example demonstrating how to programatically create a DB reference from just an id.

<?php

$id 
= new MongoId('47cc67093475061e3d9536d2');
$ref $db->createDBRef('articles'$id);
?>

Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)