private function _getMongodbCollection($config, $collection) { if (!isset(Config::config()->{$config}['db']) || !isset(Config::config()->{$config}['host']) || !isset(Config::config()->{$config}['port'])) { return 'db config error'; } try { $dbName = Config::config()->{$config}['db']; $db = new \MongoClient('mongodb://' . Config::config()->{$config}['host'] . ':' . Config::config()->{$config}['port']); $db = $db->{$dbName}; $one = $db->{$collection}->findOne(); if ($one) { $field = []; foreach ($one as $k => $v) { $field[] = $k; } return $field; } else { return 'no record for ' . $collection; } } catch (\Exception $e) { return 'connection mongodb failed'; } }
<?php /** * Created by hisune.com * Date: 2014/12/3 * Time: 15:42 * Email: hi@hisune.com */ // define application name define('APPLICATION', 'demo'); // Require bootstrap require __DIR__ . '/../app/' . ucfirst(APPLICATION) . '/bootstrap/autoload.php'; // Run try { $dispatch = new \Tiny\Dispatch(\Tiny\Config::route()); $dispatch->controller(); } catch (Exception $e) { \Tiny\Exception::exception($e); }