本文整理汇总了PHP中MongoClient::close方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoClient::close方法的具体用法?PHP MongoClient::close怎么用?PHP MongoClient::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoClient
的用法示例。
在下文中一共展示了MongoClient::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: disconnect
public function disconnect()
{
if ($this->_connection) {
$this->_connection->close();
}
$this->_db = $this->_connection = NULL;
}
示例2: __destruct
/**
* Destructor
*/
public function __destruct()
{
if (!empty($this->connection)) {
$this->connection->close(TRUE);
}
parent::__destruct();
}
示例3: like
function like($user, $id, $channel)
{
try {
$conn = new MongoClient();
$db = $conn->site;
$collection = $db->users;
$testquery = array('user_name' => $user);
$cursor = $collection->find($testquery);
if ($cursor->count() == 0) {
$info = array('user_name' => $user, '_id' => $id, 'likes' => 1);
$collection->insert($info);
$collection->update(array('user_name' => $user), array('$addToSet' => array('liked_channels' => $channel)));
echo "liked";
} else {
$collection->update(array('user_name' => $user), array('$inc' => array('likes' => 1)));
$collection->update(array('user_name' => $user), array('$addToSet' => array('liked_channels' => $channel)));
//$collection->update(array('user_name' => $user), array('$addToSet' => array('liked_channels' => $channel), '$setOnInsert' => array('$inc' => array('likes' => 1))), array('upsert' => true));
echo "liked";
}
$conn->close();
} catch (MongoConnectionException $e) {
echo 'Error connecting to MongoDB server';
} catch (MongoException $e) {
echo 'Error somewhere else with mongo';
}
//die('Error: ' . $e->getMessage()); }
exit;
}
示例4: getDb
public function getDb()
{
if (null === $this->_db) {
$options = $this->getOptions();
// caching ini file data
if (isset($options['host']) && isset($options['dbname'])) {
$url = $options['host'];
if (isset($options['port']) && $options['port']) {
$url .= ":" . $options['port'];
}
if (isset($options['username']) && $options['username']) {
$user = $options['username'] . ':';
if (isset($options['password']) && $options['username']) {
$user .= $options['password'];
}
$url = $user . "@" . $url;
}
$url = 'mongodb://' . $url;
$params = array("connect" => true);
if (isset($options['options']) && !empty($options['options'])) {
$params = $options['options'] + $params;
}
try {
$connection = new MongoClient($url, array('connect' => false) + $params);
$connection->connect();
$db = $connection->{$options}['dbname'];
$this->setDb($db);
\App::alarm()->restoreDBAlarmLog($options['dbname']);
} catch (MongoConnectionException $e) {
\App::log('Error connecting to MongoDB server: ' . $options['host']);
\App::alarm()->errorDBAlarmLog($url);
if ($connection) {
$connection->close(true);
}
throw $e;
} catch (\Exception $e) {
\App::log('Error: ' . $e->getMessage());
\App::alarm()->errorDBAlarmLog($url);
if ($connection) {
$connection->close(true);
}
throw $e;
}
}
}
return $this->_db;
}
示例5: fetchDataFromDB
function fetchDataFromDB($query)
{
$query['lrs._id'] = LRSID;
$connection = new MongoClient('mongodb://' . MDBHOST . ':' . MDBPORT, ['username' => MDBUSERNAME, 'password' => MDBPASSWORD, 'db' => MDBDB]);
//$connection = new MongoClient();
$db = $connection->selectDB(MDBDB);
$collection = $db->statements;
$cursor = $collection->find($query);
$connection->close();
return $cursor;
}
示例6: disconnect
/**
* Forcefully closes a connection to the database,
* even if persistent connections are being used.
*
* [!!] This is called automatically by [\Gleez\Mango\Client::__destruct].
*/
public function disconnect()
{
if ($this->isConnected()) {
$connections = $this->connection->getConnections();
foreach ($connections as $connection) {
// Close the connection to Mongo
$this->connection->close($connection['hash']);
}
$this->db = $this->benchmark = null;
$this->connected = false;
}
}
示例7: get_page
function get_page($pageid)
{
global $config;
$connection = new MongoClient($config["database"]["connectionstring"]);
$connection->connect();
$blog = $connection->selectDB($config["database"]["dbname"]);
$pages = $blog->pages;
$page = $pages->findOne(array("_id" => $pageid));
$connection->close();
if (!is_null($page)) {
$page["content"] = Michelf\MarkdownExtra::defaultTransform($page["content"]);
}
return $page;
}
示例8: getTreeHtmlStr
function getTreeHtmlStr()
{
$retArray = array();
array_push($retArray, '<ul id="tt" class="easyui-tree">');
try {
$mongo = new MongoClient('mongodb://nb403:27127/admin:admin');
$db = $mongo->onlineRegressionMonitor;
$collection = $db->prodVersionDetail;
$cursor = $collection->find();
$temp_arr = array();
foreach ($cursor as $doc) {
$prodName = $doc["prodName"];
$version = $doc["version"];
$tsList = $doc["tsList"];
if (count($tsList) == 0) {
continue;
}
if (!array_key_exists($prodName, $temp_arr)) {
$temp_arr[$prodName] = array();
}
$temp_arr[$prodName][$version] = $tsList;
}
foreach ($temp_arr as $prodName => $sub_arr) {
array_push($retArray, '<li data-options="attributes:{type:0}, state:\'closed\'">');
array_push($retArray, '<span>' . $prodName . '</span>');
array_push($retArray, '<ul>');
krsort($sub_arr);
foreach ($sub_arr as $version => $tsList) {
array_push($retArray, '<li data-options="attributes:{type:0}, state:\'closed\'">');
array_push($retArray, '<span>' . $version . '</span>');
array_push($retArray, '<ul>');
foreach ($tsList as $ts) {
array_push($retArray, '<li data-options="attributes:{diff_path:\'' . "{$prodName}:{$version}:{$ts}" . '\', type:1}">');
array_push($retArray, '<span>' . date("Y-m-d H:i:s", $ts) . '</span>');
array_push($retArray, '</li>');
}
array_push($retArray, '</ul>');
array_push($retArray, '</li>');
}
array_push($retArray, '</ul>');
array_push($retArray, '</li>');
}
$mongo->close();
} catch (MongoConnectionException $e) {
die($e->getMessage());
return;
}
array_push($retArray, '</ul>');
return implode("\n", $retArray);
}
示例9: mongoDelete
/**
* Delete (remove)
*/
function mongoDelete($server, $db, $collection, $id)
{
try {
$conn = new MongoClient($server);
$_db = $conn->{$db};
$collection = $_db->{$collection};
$criteria = array('_id' => new MongoId($id));
$collection->remove($criteria, array('safe' => true));
$conn->close();
return array('success' => 'deleted');
} catch (MongoConnectionException $e) {
die('Error connecting to MongoDB server');
} catch (MongoException $e) {
die('Error: ' . $e->getMessage());
}
}
示例10: MongoClient
function list_get()
{
// establish connection to MongoDB server
$connection = new MongoClient();
// select database
$db = $connection->company;
// select collection
$collection = $db->persons;
// retrieve all items in collection
$cursor = $collection->find();
if ($cursor->hasNext()) {
echo json_encode(iterator_to_array($cursor));
}
// close connection
$connection->close();
}
示例11: foreach
// a new products collection object
$collection = $db->accounts;
// fetch all product documents
$cursor = $collection->find(array('userID' => $userID));
// How many results found
$num_docs = $cursor->count();
if ($num_docs > 0) {
// loop over the results
foreach ($cursor as $obj) {
echo '_id: ' . $obj['_id'] . "\n";
echo 'user ID: ' . $obj['userID'] . "\n";
echo 'company Name: ' . $obj['companyName'] . "\n";
echo 'project name: ' . $obj['projectName'] . "\n";
echo 'isVIP: ' . $obj['isVIP'] . "\n";
echo "\n";
}
$returnValue = "Success";
echo json_encode($returnValue);
} else {
// if no accounts are found, we show this message
$returnValue = "fail 1";
echo json_encode($returnValue);
}
// close the connection to MongoDB
$conn->close();
} catch (MongoConnectionException $e) {
// if there was an error, we catch and display the problem here
echo $e->getMessage();
} catch (MongoException $e) {
echo $e->getMessage();
}
示例12: mongoList
/**
* Mongo list with sorting and filtering
*
* $select = array(
* 'limit' => 0,
* 'page' => 0,
* 'filter' => array(
* 'field_name' => 'exact match'
* ),
* 'regex' => array(
* 'field_name' => '/expression/i'
* ),
* 'sort' => array(
* 'field_name' => -1
* )
* );
*/
function mongoList($server, $db, $collection, $select = null)
{
try {
$conn = new MongoClient($server);
$_db = $conn->{$db};
$collection = $_db->{$collection};
$criteria = NULL;
// add exact match filters if they exist
if (isset($select['filter']) && count($select['filter'])) {
$criteria = $select['filter'];
}
// add regex match filters if they exist
if (isset($select['wildcard']) && count($select['wildcard'])) {
foreach ($select['wildcard'] as $key => $value) {
$criteria[$key] = new MongoRegex($value);
}
}
// get results
if ($criteria) {
$cursor = $collection->find($criteria);
} else {
$cursor = $collection->find();
}
// sort the results if specified
if (isset($select['sort']) && $select['sort'] && count($select['sort'])) {
$sort = array();
print_r($select);
foreach ($select['sort'] as $key => $value) {
$sort[$key] = (int) $value;
}
$cursor->sort($sort);
}
// set a limit
if (isset($select['limit']) && $select['limit']) {
if (MONGO_LIST_MAX_PAGE_SIZE && $select['limit'] > MONGO_LIST_MAX_PAGE_SIZE) {
$limit = MONGO_LIST_MAX_PAGE_SIZE;
} else {
$limit = $select['limit'];
}
} else {
$limit = MONGO_LIST_DEFAULT_PAGE_SIZE;
}
if ($limit) {
$cursor->limit($limit);
}
// choose a page if specified
if (isset($select['page']) && $select['page']) {
$skip = (int) ($limit * ($select['page'] - 1));
$cursor->skip($skip);
}
// prepare results to be returned
$output = array('total' => $cursor->count(), 'pages' => ceil($cursor->count() / $limit), 'results' => array());
foreach ($cursor as $result) {
// 'flattening' _id object in line with CRUD functions
$result['_id'] = $result['_id']->{'$id'};
$output['results'][] = $result;
}
$conn->close();
return $output;
} catch (MongoConnectionException $e) {
die('Error connecting to MongoDB server');
} catch (MongoException $e) {
die('Error: ' . $e->getMessage());
}
}
示例13: close
public function close()
{
$this->initialize();
return $this->mongo->close();
}
示例14: foreach
<?php
$i = 1;
foreach ($cursor as $doc) {
echo '<tr>';
echo '<td>' . $i++ . '</td>';
echo '<td>' . $doc["email"] . '</td>';
echo '<td class="center">' . $doc["message"] . '</td>';
echo '</tr>';
}
?>
<?php
$m->close();
?>
</tbody>
</table>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
示例15: attrs
//.........这里部分代码省略.........
if (isset($attrs->opening->everyday)) {
$new['opening']['everyday']['val'] = $attrs->opening->everyday->value;
$new['opening']['everyday']['from']['val'] = @$attrs->opening->everyday->from;
$new['opening']['everyday']['to']['val'] = @$attrs->opening->everyday->to;
}
if (isset($attrs->opening->somedays)) {
foreach (['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as $day) {
$new['opening']['somedays'][$day]['val'] = $attrs->opening->somedays->{$day}->value;
$new['opening']['somedays'][$day]['from']['val'] = @$attrs->opening->somedays->{$day}->from;
$new['opening']['somedays'][$day]['to']['val'] = @$attrs->opening->somedays->{$day}->to;
}
}
}
/**
* Season
*/
if (isset($attrs->season)) {
$new['season']['val'] = $attrs->season->value;
$new['season']['details']['val'] = @$attrs->season->details;
$new['season']['from']['val'] = @$attrs->season->from;
$new['season']['to']['val'] = @$attrs->season->to;
}
/**
* Berthing info
*/
if (isset($attrs->berthing)) {
// Assistance
if (isset($attrs->berthing->assistance)) {
$new['berthing']['assistance']['val'] = $attrs->berthing->assistance->value;
} else {
$new['berthing']['assistance']['val'] = 'na';
}
$new['berthing']['assistance']['details']['val'] = @$attrs->berthing->assistance->details;
// Type
if (isset($attrs->berthing->type)) {
$new['berthing']['type']['val'] = $attrs->berthing->type->values;
} else {
$new['berthing']['type']['val'] = 'na';
}
$new['berthing']['type']['details']['val'] = @$attrs->berthing->type->details;
// Seaberths
if (isset($attrs->berthing->seaberths)) {
$new['berthing']['seaberths']['total']['val'] = $attrs->berthing->seaberths->total->value;
$new['berthing']['seaberths']['visitor']['val'] = $attrs->berthing->seaberths->total->value;
}
$new['berthing']['seaberths']['details']['val'] = @$attrs->berthing->seaberths->details;
// Dryberths
if (isset($attrs->berthing->dryberths)) {
$new['berthing']['dryberths']['val'] = $attrs->berthing->dryberths->value;
$new['berthing']['dryberths']['details']['val'] = @$attrs->berthing->dryberths->details;
}
// Maxdraught
if (isset($attrs->berthing->maxdraught)) {
$new['berthing']['maxdraught']['val'] = $attrs->berthing->maxdraught->value;
$new['berthing']['maxdraught']['type']['val'] = $attrs->berthing->maxdraught->type;
$new['berthing']['maxdraught']['details']['val'] = @$attrs->berthing->maxdraught->details;
}
// Maxlength
if (isset($attrs->berthing->maxlength)) {
$new['berthing']['maxlength']['val'] = $attrs->berthing->maxlength->value;
$new['berthing']['maxlength']['type']['val'] = $attrs->berthing->maxlength->type;
$new['berthing']['maxlength']['details']['val'] = @$attrs->berthing->maxlength->details;
}
// Price
if (isset($attrs->berthing->price)) {
if (isset($attrs->berthing->price->value)) {
$new['berthing']['price']['val'] = $attrs->berthing->price->value;
$new['berthing']['price']['currency']['val'] = $attrs->berthing->price->currency;
$new['berthing']['price']['type']['val'] = $attrs->berthing->price->type;
} else {
$new['berthing']['price']['val'] = 0;
$new['berthing']['price']['currency']['val'] = 'gbp';
$new['berthing']['price']['type']['val'] = 'm';
}
$new['berthing']['price']['details']['val'] = @$attrs->berthing->price->details;
}
// Soujourn
if (isset($attrs->berthing->soujourn)) {
if (isset($attrs->berthing->soujourn->value)) {
$new['berthing']['soujourn']['val'] = $attrs->berthing->soujourn->value;
$new['berthing']['soujourn']['currency']['val'] = $attrs->berthing->soujourn->currency;
$new['berthing']['soujourn']['type']['val'] = $attrs->berthing->soujourn->type;
} else {
$new['berthing']['soujourn']['val'] = 0;
$new['berthing']['soujourn']['currency']['val'] = 'gbp';
$new['berthing']['soujourn']['type']['val'] = 'person';
}
$new['berthing']['soujourn']['details']['val'] = @$attrs->berthing->soujourn->details;
}
}
}
//$new = json_decode(json_encode($new), TRUE);
$attributes = POI::fromPostData($new);
// print_r($attributes->toDoc());
// var_dump($tbl->insert($attributes->toDoc()));
// print_r($new);
// echo "<br /><br />";
}
$con->close();
}