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
}
?>
The Mongo class
Introduction
A connection between PHP and MongoDB.
This class is used to create and manage connections. A typical use is:
<?php
$m = new Mongo(); // connect
$db = $m->foo; // get the database named "foo"
?>
See Mongo::__construct() and the section on connecting for more information about creating connections.
Class synopsis
Mongo
{
/* Constants */
/* Fields */
public
boolean
$connected
= FALSE
;
public
string
$status
= NULL
;
protected
string
$server
= NULL
;
protected
boolean
$persistent
= NULL
;
/* Methods */
__construct
([ string $server = "mongodb://localhost:27017"
[, array $options = array("connect" => TRUE)
]] )
}Predefined Constants
Mongo Constants
- Mongo::VERSION
- PHP driver version. May be suffixed with "+" or "-" if it is in-between versions.
-
Mongo::DEFAULT_HOST
"localhost" - Host to connect to if no host is given.
-
Mongo::DEFAULT_PORT
27017 - Port to connect to if no port is given.
Fields
- status
- If this is a persistent connection, if the connection was created for this object or is being reused. If this is not a persistent connection, this field should be NULL.
See Also
MongoDB core docs on » connecting.
Table of Contents
- Mongo::close — Closes this connection
- Mongo::connect — اتصال به سرور پایگاه داده
- Mongo::connectUtil — اتصال به سرور پایگاه داده
- Mongo::__construct — Creates a new database connection object
- Mongo::dropDB — حذف پایگاه داده [از رده خارح]
- Mongo::__get — Gets a database
- Mongo::getHosts — Updates status for all hosts associated with this
- Mongo::getSlave — Returns the address being used by this for slaveOkay reads
- Mongo::getSlaveOkay — Get slaveOkay setting for this connection
- Mongo::listDBs — Lists all of the databases available.
- Mongo::selectCollection — دریافت مجموعه پایگاه داده
- Mongo::selectDB — دریافت پایگاه داده
- Mongo::setSlaveOkay — Change slaveOkay setting for this connection
- Mongo::switchSlave — Choose a new slave for slaveOkay reads
- Mongo::__toString — رشته نمایشدهنده این اتصال
markh789 at gmail dot com ¶
2 years ago
