Exemple #1
0
 public function __construct($message_one, $message_two, $minlength, $maxlength)
 {
     $this->message_one = $message_one;
     $this->message_two = $message_two;
     $this->minlength = $minlength;
     $this->maxlength = $maxlength;
     $this->db = Register::get('db');
 }
Exemple #2
0
 public function createUser($id)
 {
     $key = 'user_' . $id;
     $user = Register::get($key);
     if ($user) {
         $user = new User($id);
         Register::set($key, $user);
     }
     return $user;
 }
 public static function getDataBase()
 {
     $db = Register::get('db');
     if (!$db) {
         // 单例模式
         $db = new Database\MySQLi();
         $db->connect('127.0.0.1', 'root', '123456', 'test');
         Register::set('db', $db);
     }
     return $db;
 }
Exemple #4
0
 /**
  * 数据库工厂方法
  */
 public static function getDatabase($id = 'master')
 {
     //读取数据库配置文件
     if ($id == 'master') {
         $db_conf = Init::getInstance()->config['DataBase']['master'];
     } else {
         $db_conf = Init::getInstance()->config['DataBase']['slave'];
     }
     $key = 'database_' . $id;
     //获取数据库对象
     $db = Register::get($key);
     if (!$db) {
         $db = new MySQLi();
         $db->connect($db_conf['host'], $db_conf['user'], $db_conf['password'], $db_conf['dbname']);
         Register::set($key, $db);
     }
     return $db;
 }
Exemple #5
0
 static function getDatabase($id = 'proxy')
 {
     if ($id == 'proxy') {
         if (!self::$proxy) {
             self::$proxy = new \IMooc\Database\Proxy();
         }
         return self::$proxy;
     }
     $key = 'database_' . $id;
     if ($id == 'slave') {
         $slaves = Application::getInstance()->config['database']['slave'];
         $db_conf = $slaves[array_rand($slaves)];
     } else {
         $db_conf = Application::getInstance()->config['database'][$id];
     }
     $db = Register::get($key);
     if (!$db) {
         $db = new Database\MySQLi();
         $db->connect($db_conf['host'], $db_conf['user'], $db_conf['password'], $db_conf['dbname']);
         Register::set($key, $db);
     }
     return $db;
 }
Exemple #6
0
<?php

require __DIR__ . '/Register.php';
$registers = ['school', 'industry'];
foreach ($registers as $register) {
    $url = sprintf('http://%s.openregister.org/records.csv', $register);
    print "Fetching {$url}\n";
    $output = sprintf('data/%s.ndjson', $register);
    $client = new Register($url);
    $client->get(['page-size' => 5000], $output);
}