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; }
private static function get($query) { $db = Db::getInstance(); $req = $db->prepare($query); $req->execute(); return $req->fetchAll(PDO::FETCH_CLASS, '\\model\\Date'); }
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]; }
function __construct() { $this->db = \lib\Db::getInstance(); }
public function __construct() { $this->db = \lib\Db::getInstance(); $this->twitter = new \cron\Twitter(); $this->ircBot = new \cron\IrcBot(); }
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(); }
/** * 切换当前的数据库连接 * @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; }