예제 #1
0
파일: Dow.php 프로젝트: Eupeodes/gh
 public static function getNew()
 {
     $file = explode('/', dirname(__FILE__));
     array_pop($file);
     $response = false;
     if (debug_backtrace()[0]['file'] === implode('/', $file) . '/cron.php') {
         $db = \lib\Db::getInstance();
         $date = \model\Date::max(false);
         if (\model\Date::nextCheck($date, 0) <= 0) {
             $dateTime = new \DateTime($date);
             $req = $db->prepare('INSERT INTO dow VALUES (:date, :dow)');
             while (true) {
                 $url = "http://geo.crox.net/djia/" . str_replace("-", "/", $date);
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $url);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, true);
                 $dow = curl_exec($ch);
                 curl_close($ch);
                 if ($dow > 0) {
                     $req->execute([':date' => $date, ':dow' => $dow]);
                     $response = true;
                     $dateTime->add(new \DateInterval('P1D'));
                     $date = $dateTime->format('Y-m-d');
                 } else {
                     break;
                 }
             }
         }
     }
     return $response;
 }
예제 #2
0
파일: Date.php 프로젝트: Eupeodes/gh
 private static function get($query)
 {
     $db = Db::getInstance();
     $req = $db->prepare($query);
     $req->execute();
     return $req->fetchAll(PDO::FETCH_CLASS, '\\model\\Date');
 }
예제 #3
0
파일: Page.php 프로젝트: Eupeodes/gh
 public static function get($url)
 {
     $db = Db::getInstance();
     $query = 'SELECT * FROM page WHERE url=:url';
     $req = $db->prepare($query);
     $req->bindParam(':url', $url, PDO::PARAM_STR);
     $req->execute();
     $res = $req->fetchAll(PDO::FETCH_CLASS, '\\model\\Page');
     return $res[0];
 }
예제 #4
0
파일: IrcBot.php 프로젝트: Eupeodes/gh
 function __construct()
 {
     $this->db = \lib\Db::getInstance();
 }
예제 #5
0
파일: Wiki.php 프로젝트: Eupeodes/gh
 public function __construct()
 {
     $this->db = \lib\Db::getInstance();
     $this->twitter = new \cron\Twitter();
     $this->ircBot = new \cron\IrcBot();
 }
예제 #6
0
파일: Twitter.php 프로젝트: Eupeodes/gh
 public function __construct()
 {
     $this->connection = new \lib\external\Twitter(\config::$keys['twitter']['consumerKey'], \config::$keys['twitter']['consumerSecret'], \config::$keys['twitter']['accessToken'], \config::$keys['twitter']['accessTokenSecret']);
     $this->db = \lib\Db::getInstance();
     $this->shortUrlLength();
 }
예제 #7
0
 /**
  * 切换当前的数据库连接
  * @access public
  * @param integer $linkNum  连接序号
  * @param mixed $config  数据库连接信息
  * @param boolean $force 强制重新连接
  * @return Model
  */
 public function db($linkNum = '', $config = '', $force = false)
 {
     if ('' === $linkNum && $this->db) {
         return $this->db;
     }
     if (!isset($this->_db[$linkNum]) || $force) {
         // 创建一个新的实例
         if (!empty($config) && is_string($config) && false === strpos($config, '/')) {
             // 支持读取配置参数
             $config = C($config);
         }
         $this->_db[$linkNum] = Db::getInstance($config);
     } elseif (null === $config) {
         $this->_db[$linkNum]->close();
         // 关闭数据库连接
         unset($this->_db[$linkNum]);
         return;
     }
     // 切换数据库连接
     $this->db = $this->_db[$linkNum];
     $this->_after_db();
     // 字段检测
     if (!empty($this->name) && $this->autoCheckFields) {
         $this->_checkTableInfo();
     }
     return $this;
 }