/** * getMysql [mysql实例] * @author wangzhiqiang * @return Mysql */ public function getMysql() { if (empty($this->mysql)) { $this->mysql = new Mysql(Config::get_mysql_config()); } return $this->mysql; }
/** * getRedis [redis实例] * @author wangzhiqiang * @return \Redis */ private function getRedis() { if (empty($this->redis) || !$this->redis->info()) { $this->redis = new \Redis(); $config = Config::get_redis_config(); $res = $this->redis->connect($config['host'], $config['port']); $this->redis->auth($config['password']); if (!$res) { } } return $this->redis; }
/** * Database connections module. * * @category Asymptix PHP Framework * @author Dmytro Zarezenko <*****@*****.**> * @copyright (c) 2009 - 2015, Dmytro Zarezenko * * @git https://github.com/Asymptix/Framework * @license http://opensource.org/licenses/MIT */ use Asymptix\db\DBCore; use conf\Config; $mysqli = new mysqli(Config::getDBConfigParam('HOST'), Config::getDBConfigParam('USER'), Config::getDBConfigParam('PASSWORD'), Config::getDBConfigParam('DBNAME')); if ($mysqli->connect_error) { die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error); } else { if (!$mysqli->set_charset(Config::getDBConfigParam('DB_CHARSET'))) { printf("Error loading character set " . Config::getDBConfigParam('DB_CHARSET') . ": %s\n", $mysqli->error); } $manager = DBCore::getInstance(); DBCore::connection($mysqli); //$manager->setCurrentConnection('first'); } // Register a shutdown function which will close DB connection register_shutdown_function(function () { global $manager; $conns = $manager->getConnections(); foreach ($conns as $connResource) { $manager->closeConnection($connResource); } });