close() public method

Closes this connection
public close ( boolean | string $connection = null ) : boolean
$connection boolean | string - If connection is not given, or FALSE then connection that would be selected for writes would be closed. In a single-node configuration, that is then the whole connection, but if you are connected to a replica set, close() will only close the connection to the primary server.
return boolean - Returns if the connection was successfully closed.
Example #1
0
 public function disconnect()
 {
     if ($this->_connection) {
         $this->_connection->close();
     }
     $this->_db = $this->_connection = NULL;
 }
Example #2
0
 /**
  * Destructor
  */
 public function __destruct()
 {
     if (!empty($this->connection)) {
         $this->connection->close(TRUE);
     }
     parent::__destruct();
 }
Example #3
0
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;
}
Example #4
0
 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;
 }
Example #5
0
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;
}
Example #6
0
 /**
  * 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;
     }
 }
Example #7
0
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;
}
Example #8
0
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);
}
Example #9
0
/**
 * 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());
    }
}
Example #10
0
 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();
 }
    // 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();
}
Example #12
0
/**
 * 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());
    }
}
Example #13
0
 public function close()
 {
     $this->initialize();
     return $this->mongo->close();
 }
<?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 -->
Example #15
0
 function attrs()
 {
     $this->load->library('POI');
     $this->load->library('geo/*');
     $this->load->model('POIModel');
     $pois = POIModel::loadAll();
     $con = new MongoClient();
     $db = $con->pocketsail;
     $tbl = $db->poi;
     $tbl->remove([]);
     $tbl->ensureIndex(['id' => 1, 'lat' => 1, 'lng' => 1, 'contact.type' => 1]);
     foreach ($pois as $poi) {
         //            $id = $poi->id();
         //            $url = $poi->url();
         //            $name = $poi->name();
         //            $label = $poi->label();
         //            $nearId = $poi->nearId();
         //            $countryId = $poi->countryId();
         //            $cat = $poi->cat();
         //            $sub = $poi->sub();
         //            $userId = $poi->userId();
         //            $lat = $poi->lat();
         //            $lng = $poi->lng();
         //            $border = $poi->border();
         //            $rank = $poi->rank();
         //            $timestamp = $poi->timestamp();
         $attrs = $poi->attrs();
         $new = [];
         $new['id'] = (int) $poi->id();
         $new['url'] = (string) $poi->url();
         $new['name'] = (string) $poi->name();
         $new['label'] = (string) $poi->label();
         $new['near'] = (string) $poi->nearName();
         $new['country'] = (string) $poi->countryName();
         $new['cat'] = (string) $poi->cat();
         $new['sub'] = (string) $poi->cat();
         $new['lat'] = (double) $poi->lat();
         $new['lng'] = (double) $poi->lng();
         if (gettype($attrs) === 'object') {
             /**
              * Description
              */
             if (isset($attrs->description->details)) {
                 $new["description"] = $attrs->description->details;
             }
             /**
              * Approach
              */
             if (isset($attrs->approach)) {
                 $new['approach']['text'] = $attrs->approach->details;
                 $new['approach']['drying']['value'] = @$attrs->approach->drying->value;
                 $new['approach']['drying']['details'] = @$attrs->approach->drying->details;
             }
             /**
              * Hazards
              */
             if (isset($attrs->hazards->details)) {
                 $new['hazards']['val'] = $attrs->hazards->details;
             }
             /**
              * Exposure
              */
             if (isset($attrs->exposure)) {
                 // Wind
                 $winds = explode(",", @$attrs->exposure->wind);
                 if (count($winds) > 0 && $winds[0] != "") {
                     //                        echo "Specific, yet ";
                     //                        print_r($winds);
                     $new['exposure']['wind']['value'] = 'specific';
                     foreach ($winds as $wind) {
                         $new['exposure']['wind']['dir'][] = trim($wind);
                     }
                 } else {
                     $new['exposure']['wind']['value'] = 'na';
                 }
                 // Swell
                 $swells = explode(",", @$attrs->exposure->swell);
                 if (count($swells) > 0) {
                     $new['exposure']['swell']['value'] = 'specific';
                     foreach ($swells as $swell) {
                         $new['exposure']['swell']['dir'][] = trim($swell);
                     }
                 } else {
                     $new['exposure']['swell']['value'] = 'na';
                 }
             }
             /**
              * Attractions & Nightlife
              */
             if (isset($attrs->attractions->details)) {
                 $new['attractions'] = $attrs->attractions->details;
             }
             /**
              * Nightlife
              */
             if (isset($attrs->nightlife->details)) {
                 $new['nightlife'] = $attrs->nightlife->details;
             }
             /**
              * Contact
              */
             if (isset($attrs->contact->types)) {
                 $new['contact']['type'] = [];
                 $new['contact']['value'] = [];
                 for ($i = 0; $i < count($attrs->contact->types); $i++) {
                     $new['contact']['value'][] = $attrs->contact->values[$i];
                     $new['contact']['type'][] = $attrs->contact->types[$i];
                 }
             }
             /**
              * Facilities
              */
             if (isset($attrs->facilities->water->value)) {
                 $new['facilities']['water']['val'] = $attrs->facilities->water->value;
                 $new['facilities']['water']['details']['val'] = @$attrs->facilities->water->details;
             }
             if (isset($attrs->facilities->electricity->value)) {
                 $new['facilities']['electricity']['val'] = $attrs->facilities->electricity->value;
                 $new['facilities']['electricity']['details']['val'] = @$attrs->facilities->electricity->details;
             }
             if (isset($attrs->facilities->showers->value)) {
                 $new['facilities']['showers']['val'] = $attrs->facilities->showers->value;
                 $new['facilities']['showers']['details']['val'] = @$attrs->facilities->showers->details;
             }
             if (isset($attrs->facilities->toilets->value)) {
                 $new['facilities']['toilets']['val'] = $attrs->facilities->toilets->value;
                 $new['facilities']['toilets']['details']['val'] = @$attrs->facilities->toilets->details;
             }
             if (isset($attrs->facilities->waste->value)) {
                 $new['facilities']['waste']['val'] = $attrs->facilities->waste->value;
                 $new['facilities']['waste']['details']['val'] = @$attrs->facilities->waste->details;
             }
             if (isset($attrs->facilities->reception->value)) {
                 $new['facilities']['reception']['val'] = $attrs->facilities->reception->value;
                 $new['facilities']['reception']['details']['val'] = @$attrs->facilities->reception->details;
             }
             if (isset($attrs->facilities->customs->value)) {
                 $new['facilities']['customs']['val'] = $attrs->facilities->customs->value;
                 $new['facilities']['customs']['details']['val'] = @$attrs->facilities->customs->details;
             }
             if (isset($attrs->facilities->enquiries->value)) {
                 $new['facilities']['enquiries']['val'] = $attrs->facilities->enquiries->value;
                 $new['facilities']['enquiries']['details']['val'] = @$attrs->facilities->enquiries->details;
             }
             if (isset($attrs->facilities->laundry->value)) {
                 $new['facilities']['laundry']['val'] = $attrs->facilities->laundry->value;
                 $new['facilities']['laundry']['details']['val'] = @$attrs->facilities->laundry->details;
             }
             if (isset($attrs->facilities->wifi->value)) {
                 $new['facilities']['wifi']['val'] = $attrs->facilities->wifi->value;
                 $new['facilities']['wifi']['details']['val'] = @$attrs->facilities->wifi->details;
             }
             if (isset($attrs->facilities->disability->value)) {
                 $new['facilities']['disability']['val'] = $attrs->facilities->disability->value;
                 $new['facilities']['disability']['details']['val'] = @$attrs->facilities->disability->details;
             }
             if (isset($attrs->facilities->pets->value)) {
                 $new['facilities']['pets']['val'] = $attrs->facilities->pets->value;
                 $new['facilities']['pets']['details']['val'] = @$attrs->facilities->pets->details;
             }
             /**
              * Sources
              */
             if (isset($attrs->sources->details)) {
                 $sources = explode("\r\n", $attrs->sources->details);
                 foreach ($sources as $source) {
                     $new['sources'][] = trim($source);
                 }
             }
             /**
              * Charts
              */
             if (isset($attrs->charts->details)) {
                 $chartsStr = trim($attrs->charts->details, " .");
                 $charts = explode(",", $chartsStr);
                 foreach ($charts as $chart) {
                     $charts_and = $charts = explode(" and ", $chart);
                     foreach ($charts_and as $chart_and) {
                         $new['charts'][] = trim($chart_and, " .");
                     }
                 }
             }
             /**
              * Anchoring info
              */
             if (isset($attrs->anchoring)) {
                 $new['anchoring']['depth']['from'] = $attrs->anchoring->depth->from;
                 $new['anchoring']['depth']['to'] = $attrs->anchoring->depth->to;
                 $new['anchoring']['holding']['value'] = @$attrs->anchoring->holding->values;
                 $new['anchoring']['holding']['details'] = @$attrs->anchoring->holding->details;
                 $new['anchoring']['cost']['value'] = @$attrs->anchoring->price->value !== "";
                 $new['anchoring']['cost']['price'] = @$attrs->anchoring->price->value;
                 $new['anchoring']['cost']['currency'] = @$attrs->anchoring->price->currency;
                 $new['anchoring']['cost']['type'] = @$attrs->anchoring->price->type;
                 $new['anchoring']['cost']['details'] = @$attrs->anchoring->price->details;
                 $new['anchoring']['tax']['value'] = @$attrs->berthing->soujourn->value;
                 $new['anchoring']['tax']['currency'] = @$attrs->berthing->soujourn->currency;
                 $new['anchoring']['tax']['type'] = @$attrs->berthing->soujourn->type;
                 $new['anchoring']['tax']['details'] = @$attrs->berthing->soujourn->details;
             }
             /**
              * Buoys mooring
              */
             if (isset($attrs->mooring)) {
                 $new['mooring']['number']['val'] = $attrs->mooring->number->value;
                 $new['mooring']['number']['details']['val'] = @$attrs->mooring->number->details;
                 $new['mooring']['maxdraught']['val'] = $attrs->mooring->maxdraught->value;
                 $new['mooring']['maxdraught']['type']['val'] = $attrs->mooring->maxdraught->type;
                 $new['mooring']['maxdraught']['details']['val'] = @$attrs->mooring->maxdraught->details;
                 $new['mooring']['maxlength']['val'] = $attrs->mooring->maxlength->value;
                 $new['mooring']['maxlength']['type']['val'] = $attrs->mooring->maxlength->type;
                 $new['mooring']['maxlength']['details']['val'] = @$attrs->mooring->maxlength->details;
                 $new['mooring']['price']['val'] = @$attrs->mooring->price->value;
                 $new['mooring']['price']['currency']['val'] = @$attrs->mooring->price->currency;
                 $new['mooring']['price']['type']['val'] = @$attrs->mooring->price->type;
                 $new['mooring']['price']['details']['val'] = @$attrs->mooring->price->details;
                 $new['mooring']['soujourn']['val'] = @$attrs->mooring->soujourn->value;
                 $new['mooring']['soujourn']['currency']['val'] = @$attrs->mooring->soujourn->currency;
                 $new['mooring']['soujourn']['type']['val'] = @$attrs->mooring->soujourn->type;
                 $new['mooring']['soujourn']['details']['val'] = @$attrs->mooring->soujourn->details;
             }
             /**
              * Berthing, mooring, anchoring
              */
             if (isset($attrs->mba->details) && $attrs->mba->details !== '') {
                 $new['bma']['val'] = $attrs->mba->details;
             }
             /**
              * Services
              */
             if (isset($attrs->services->slipway->value)) {
                 $new['services']['slipway']['val'] = $attrs->services->slipway->value;
                 $new['services']['slipway']['details']['val'] = @$attrs->services->slipway->details;
             }
             if (isset($attrs->services->pumpout->value)) {
                 $new['services']['pumpout']['val'] = $attrs->services->pumpout->value;
                 $new['services']['pumpout']['details']['val'] = @$attrs->services->pumpout->details;
             }
             if (isset($attrs->services->repairs->value)) {
                 $new['services']['repairs']['val'] = $attrs->services->repairs->value;
                 $new['services']['repairs']['details']['val'] = @$attrs->services->repairs->details;
             }
             if (isset($attrs->services->travelift->value)) {
                 $new['services']['travelift']['val'] = $attrs->services->travelift->value;
                 $new['services']['travelift']['maxtonnage']['val'] = @$attrs->services->travelift->maxtonnage;
                 $new['services']['travelift']['details']['val'] = @$attrs->services->travelift->details;
             }
             if (isset($attrs->services->storage->value)) {
                 $new['services']['storage']['val'] = $attrs->services->storage->value;
                 $new['services']['storage']['details']['val'] = @$attrs->services->storage->details;
             }
             if (isset($attrs->services->divers->value)) {
                 $new['services']['divers']['val'] = $attrs->services->divers->value;
                 $new['services']['divers']['details']['val'] = @$attrs->services->divers->details;
             }
             /**
              * Opening
              */
             if (isset($attrs->opening)) {
                 $new['opening']['val'] = $attrs->opening->value;
                 $new['opening']['details']['val'] = @$attrs->opening->details;
                 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();
 }
****************************************************/
$email = $_POST["email"];
if ($email == "") {
    die(" email cannot be empty");
}
$password = $_POST["password"];
if ($password == "") {
    die("password cannot be empty");
}
$con = new MongoClient();
if ($con) {
    $db = $con->{$users};
    $selection = $db->{$myusers};
    $document = array("email" => $email, "password" => $password);
    $result = $selection->findOne($document);
    if ($result) {
        $success = "You are successully loggedIn";
        $res = $selection->find($document);
        foreach ($res as $doc) {
            echo $doc["_id"] . "<br />";
            echo $doc["name"] . "<br />";
            echo $doc["username"] . "<br />";
        }
    } else {
        die("user does not exi44st , or user / password is incorrect");
    }
} else {
    die("Mongo DB not installed");
}
$con->close();
Example #17
0
$info = $_POST["infoWindow"];
/* Create object to store */
$marker = array('latitude' => $lat, 'longitude' => $long, 'incident' => $incident, 'notes' => $notes, 'time' => $time, 'date' => $date, 'info' => $info);
/* Standard options */
$uri = "mongodb://*****:*****@ds041581.mongolab.com:41581/echo";
$options = array("connectTimeoutMS" => 30000);
/* Create Mongo connection with URI and options*/
$client = new MongoClient($uri, $options);
/* Reference the proper database */
$db = $client->selectDB("echo");
/* Reference the proper collection */
$report = $db->reports;
// To insert a dict, use the insert method.
$report->insert($marker);
// Only close the connection when your app is terminating
$client->close();
// TWILIO API --------------------------------------------------------------------------------------------------
/* Send an SMS using Twilio. You can run this file 3 different ways:
 *
 * - Save it as sendnotifications.php and at the command line, run 
 *        php sendnotifications.php
 *
 * - Upload it to a web host and load mywebhost.com/sendnotifications.php 
 *   in a web browser.
 * - Download a local server like WAMP, MAMP or XAMPP. Point the web root 
 *   directory to the folder containing this file, and load 
 *   localhost:8888/sendnotifications.php in a web browser.
 */
// Step 1: Download the Twilio-PHP library from twilio.com/docs/libraries,
// and move it into the folder containing this file.
require "Twilio.php";
Example #18
0
//echo 'per limit: ', $pageMax, PHP_EOL;
$config = (require PROJECT_ROOT . 'config' . DS . 'db.php');
$from_config = $config['db'][$config['db']['adapter']];
$to_config = $config['db2'][$config['db2']['adapter']];
//连接mongodb
try {
    $mongoClient = new \MongoClient($from_config['dsn']);
    // $node_collection = $mongoClient->selectCollection($from_config['db'], 'MEMBER_NODE');
} catch (Exception $e) {
    echo $e->getMessage();
    return;
}
//连接mysql server
$to_conn = mysqli_connect($to_config['host'], $to_config['usernmae'], $to_config['password']);
if (!$to_conn) {
    $mongoClient->close();
    die(mysqli_error($to_conn));
}
mysqli_select_db($to_config['db'], $to_conn);
//读取数据
$queries = [];
foreach ($table_list as $table => $entity) {
    $queries = array_merge($queries, create_queries($from_config['db'], $table, $start, $end, $entity, $per_limit));
}
//开启事务
$to_conn->autocommit(false);
$to_conn->begin_transaction();
$flag = $to_conn->commit();
if (!$flag) {
    $to_conn->rollback();
}
Example #19
0
    try {
        $db_url = "mongodb://localhost:27017";
        $connect = new MongoClient($db_url);
        $db_name = "amazon";
        $db = $connect->selectDB($db_name);
        $collection = $db->selectCollection("products");
        $data = $collection->findOne(array("pid" => $pid));
        if (isset($data)) {
            $size = sizeof($data['price']);
            // echo $size;
            for ($x = 0; $x < $size; $x++) {
                echo "{ x: datetimeToDate(\"" . $data['timestamp'][$x] . "\"), y: " . str_replace(",", "", $data['price'][$x]) . "}," . "\n";
            }
        }
        // disconnect from server
        $connect->close();
    } catch (MongoConnectionException $e) {
        die('Cannot connect to MongoDB server');
    } catch (MongoException $e) {
        die('Mongo Error: ' . $e->getMessage());
    } catch (Exception $e) {
        die('Error: ' . $e->getMessage());
    }
}
?>
        ]
      }
      
      
      ]
    });
Example #20
0
function deletePerson($id)
{
    try {
        global $mongoHost;
        $connection = new MongoClient($mongoHost);
        $db = $connection->Equipments;
        $collection = $db->Peoples;
        $collection->remove(array('_id' => new MongoId($id)));
        $connection->close();
    } catch (MongoConnectionException $e) {
        echo $e->getMessage();
    } catch (MongoException $e) {
        echo $e->getMessage();
    }
}
Example #21
0
<?php

require_once 'config.php';
$agent = '*****@*****.**';
$connection = new MongoClient('mongodb://' . MDBHOST . ':' . MDBPORT, ['username' => MDBUSERNAME, 'password' => MDBPASSWORD, 'db' => MDBDB]);
//$connection = new MongoClient();
$db = $connection->selectDB(MDBDB);
$collection = $db->statements;
$query = array('statement.actor.mbox' => 'mailto:' . $agent, 'statement.verb.id' => 'http://activitystrea.ms/schema/1.0/create', 'statement.object.definition.type' => 'http://adlnet.gov/expapi/activities/course');
$lrsid = LRSID;
$query['lrs._id'] = $lrsid;
$cursor = $collection->find($query);
$connection->close();
$courses = array();
foreach ($cursor as $document) {
    $courses[] = $document['statement'];
}
$uniquecourses = array();
foreach ($courses as $course) {
    if (!array_key_exists($course['object']['id'], $uniquecourses)) {
        $uniquecourses[$course['object']['id']] = $course;
    }
}
?>


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
Example #22
0
 /**
  * Close the connection to Mongo
  *
  * @return  boolean  if the connection was successfully closed
  */
 public function close()
 {
     if ($this->_connected) {
         $this->_connected = $this->_connection->close();
         $this->_db = "{$this->_db}";
     }
     return $this->_connected;
 }
Example #23
0
$lines = file("../data/members.txt");
$userCount = count($lines);
foreach ($lines as $line) {
    $line = trim($line);
    list($name, $mail) = explode(":", $line);
    $nameList[$name] = 0;
}
try {
    $mongo = new MongoClient('mongodb://nb403:27127/admin:admin');
    $db = $mongo->youdaoSports;
    $collection = $db->votes;
    $doc = $collection->findOne(array("_id" => new MongoId($id)));
    foreach ($doc["users"] as $user) {
        $nameList[$user] = 1;
    }
    $mongo->close();
} catch (MongoConnectionException $e) {
    die($e->getMessage());
    return;
}
?>

<table border='1'>
<tr>
    <th>成员名</th>
    <th>支持</th>
    <th>反对</th>
</tr>
<?php 
foreach ($nameList as $name => $val) {
    if ($val == 0) {
Example #24
0
 /**
  * You should never call this function.
  *
  * The PHP driver will handle connections automatically, and will
  * keep this performant for you.
  */
 public function close()
 {
     if (!empty($this->_mongo)) {
         $this->_mongo->close();
     }
 }