Example #1
0
 private static function connect()
 {
     self::$instance = new self();
     $config = Config::getInstance();
     self::$instance = new \Mongo("mongodb://" . $config['db_host'] . ":" . $config['db_port'] . "/" . $config['db_database']);
     if (!self::$instance) {
         throw new \RuntimeException("Ошибка подключения к базе данных: ");
     }
 }
Example #2
0
 public static function connect()
 {
     self::$instance = new self();
     $config = Config::getInstance();
     self::$instance->connection = mysqli_connect($config->get('host'), $config->get('username'), $config->get('password'), $config->get('database'));
     if (!self::$instance->connection) {
         throw new \RuntimeException("Ошибка подключения к базе данных: " . mysqli_error(self::$instance->connection));
     }
     return self::$instance;
 }
Example #3
0
 public function __construct()
 {
     try {
         $nameDB = Config::getInstance()->get('name');
         $hostDB = Config::getInstance()->get('host');
         $user = Config::getInstance()->get('user');
         $pass = Config::getInstance()->get('pass');
         $argument = sprintf("mysql:dbname=%s;host=%s;", $nameDB, $hostDB);
         $this->conn = new \PDO($argument, $user, $pass);
     } catch (PDOException $e) {
         print "¡Error!: " . $e->getMessage() . "<br/>";
         die;
     }
 }
Example #4
0
 public function add_forecast()
 {
     $api = new \models\ApiModel();
     $towns = $api->getCities();
     $config = \config\Config::getInstance();
     $db = new \Mongo("mongodb://" . $config['db_host'] . ":" . $config['db_port'] . "/" . $config['db_database']);
     $collection = $db->selectCollection('ngs', 'forecasts');
     foreach ($towns as $town) {
         $decoded = $api->getForecast($town['name']);
         foreach ($decoded['forecasts'] as $forecasts) {
             foreach ($forecasts['hours'] as $hours) {
                 if ($hours['hour'] == '12') {
                     $mas = array('temperature' => $hours['temperature']['avg'], 'pressure' => $hours['pressure']['avg'], 'humidity' => $hours['humidity']['avg'], 'wind' => array('speed' => $hours['wind']['speed']['avg'], 'direction' => $hours['wind']['direction']['title']), 'cloud' => $hours['cloud']['title'], 'precipitation' => $hours['precipitation']['title']);
                 }
             }
             $document = array('date' => new \MongoDate(strtotime($forecasts['date'])), 'city' => $town['name'], 'forecast' => $mas);
             $collection->update(array('city' => $document['city'], 'date' => $document['date']), array('$set' => $document), array('upsert' => true));
         }
     }
 }
 function __construct()
 {
     $db = Config::getInstance()->getBDD('bdd.path');
     return new \PDO('sqlite:' . $db);
 }