public function __construct($db_config = null) { if (is_array($db_config) && (isset($db_config['host']) || isset($db_config['dsn']))) { if (!isset($db_config['dsn'])) { if (!isset($db_config['adapter'])) { $this->adapter = 'mysql'; } $dsn = $this->adapter . ":host=" . $db_config['host'] . ";port=" . $db_config['port']; if (isset($db_config['dbname'])) { $dsn .= ";dbname=" . $db_config['dbname']; } $options = array(); if ($this->adapter == 'mysql') { $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $db_config['enCode']); } $this->connect($dsn, $db_config['username'], $db_config['password'], $options); } else { $this->connect($db_config['dsn'], $db_config['username'], $db_config['password'], array()); } } elseif (is_string($db_config)) { $dsn = $db_config; $username = ''; $password = ''; $this->connect($dsn, $username, $password); } $this->logger = WF_Registry::get('logger'); }
public function db() { if ($this->db == null) { $this->db = WF_Registry::get('db'); } return $this->db; }
public function __construct() { $this->prj = new Tags_project('tcms.interface.tags'); WF_Registry::set('db', $this->prj->CData->CDb->r); $this->tagsController = $this->prj->rs->data->ext['tags']; $redis = WF_Registry::get('redis'); $redis->flushAll(); }
public static function fire($name, $data = array()) { $event = new WF_Event($name, $data); if (isset(self::$handlers[$name])) { foreach (self::$handlers[$name] as $callback) { try { call_user_func($callback, $event); } catch (Exception $e) { $logger = WF_Registry::get('logger'); if ($logger) { $logger->warn("call " . WF_Util::getFuncName($callback) . " failed\n"); } } } } }
public function query($sql, $params = array()) { $logger = WF_Registry::get('logger'); $logger->debug("sql query result: '{$sql} (" . implode(', ', $params) . ")' rowset count:"); if (!$this->conn) { return false; } $stmt = $this->conn->prepare($sql); if (!$stmt) { $logger->error("sql prepare failed '{$sql}'"); $logger->error("db error:" . $this->conn->errorCode() . ' ' . json_encode($this->conn->errorInfo())); return false; } $result = $stmt->execute($params); if (!$result) { $logger->error("sql query failed '{$sql} (" . implode(', ', $params) . ")'"); $logger->error("db error:" . $stmt->errorCode() . ' ' . json_encode($stmt->errorInfo())); } return $stmt; }
function __construct($project) { $this->cache = $project->CData->CCache; $this->logger = WF_Registry::get('logger'); }
public function tableName() { $prefix = WF_Registry::get('prefix', 'tbl_'); return $prefix . "article_tags"; }
protected function getDb() { if ($this->db == null) { $this->db = WF_Registry::get('db'); } return $this->db; }
public function getLogger() { if ($this->logger) { return $this->logger; } return WF_Registry::get('logger'); }