downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Mongo::close> <コアクラス群
[edit] Last updated: Fri, 25 May 2012

view this page in

Mongo クラス

(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)

導入

MongoDB と PHP を接続します。

このクラスを使用して接続を確立します。使い方は次のようになります。

<?php

$m 
= new Mongo(); // 接続
$db $m->foo// "foo" というデータベースの取得

?>

接続の作成に関する詳細な情報は Mongo::__construct() および接続 の節を参照ください。

クラス概要

Mongo {
/* 定数 */
const string VERSION ;
const string DEFAULT_HOST = "localhost" ;
const int DEFAULT_PORT = 27017 ;
/* フィールド */
public boolean $connected = FALSE ;
public string $status = NULL ;
protected string $server = NULL ;
protected boolean $persistent = NULL ;
/* メソッド */
public bool close ( void )
public bool connect ( void )
protected bool connectUtil ( void )
public __construct ([ string $server = "mongodb://localhost:27017" [, array $options = array("connect" => TRUE) ]] )
public array dropDB ( mixed $db )
public MongoDB __get ( string $dbname )
public array getHosts ( void )
public static int getPoolSize ( void )
public string getSlave ( void )
public bool getSlaveOkay ( void )
public array listDBs ( void )
public array poolDebug ( void )
public MongoCollection selectCollection ( string $db , string $collection )
public MongoDB selectDB ( string $name )
public static bool setPoolSize ( int $size )
public bool setSlaveOkay ([ bool $ok = true ] )
public string switchSlave ( void )
public string __toString ( void )
}

定義済み定数

Mongo Constants

Mongo::VERSION
PHP ドライバのバージョン。中間バージョンの場合は最後に "+" や "-" がつくことがあります。
Mongo::DEFAULT_HOST
"localhost"
ホストを指定しない場合に接続するホスト。
Mongo::DEFAULT_PORT
27017
ポートを指定しない場合に接続するポート。

フィールド

status
この接続が持続的なものである場合は、 接続が今回新しく作られたのか以前のものを再利用しているのか。 持続的な接続でない場合は、このフィールドは NULL となります。

参考

MongoDB コアドキュメントの » 接続 を参照ください。

目次



add a note add a note User Contributed Notes Mongo
Fausto Vanin @faustovanin 09-Feb-2011 07:31
For those who are concerned on parsing JSON associative arrays from queries, this class could be useful. You just have to extend it and call parent constructor and it gets the job done.
It automatically initializes all your object attributes getting values from the array.

<?php

   
#doc
    #    classname:    MongoClass
    #    scope:        PUBLIC
    #
    #/doc
   
   
class MongoClass
   
{
       
#    internal variables
       
protected $id;
       
       
#    Constructor
       
function __construct ($attList = array())
        {
           
$reflection = new ReflectionObject($this);

            foreach (
$attList as $attName => $attValue)
            {
               
$attObj = $reflection->getProperty($attName);
               
$attObj->setAccessible(true);
               
$attObj->setValue($this, $attValue);
            }
        }
       
###   
   
   
}
   
###
       
class A extends MongoClass {
                private
$name;
                private
$value;
                private
$weight;

                public function
__construct($attList) {
                       
parent::__construct($attList);
                }
        }

       
$attList = array(
               
"name" => "Beer",
               
"value" => "Delicious",
               
"weight" => 15.2
       
); //This is your JSON object associative aray

       
$a = new A($attList);

?>
markh789 at gmail dot com 07-Jan-2011 05:32
Here is a simple connection function :)

<?php
function MongoConnect($username, $password, $database, $host) {
   
$con = new Mongo("mongodb://{$username}:{$password}@{$host}"); // Connect to Mongo Server
   
$db = $con->selectDB($database); // Connect to Database
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites