2 Star 2 Fork 0

纸喵软件 / frame-php

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Data.php 1.59 KB
Copy Edit Web IDE Raw Blame History
倒霉狐狸(公司PC) authored 2018-11-27 09:28 . feat: 提交纸喵框架
<?php
/**
* 数据
* Created by PhpStorm.
* User: 倒霉狐狸
* Date: 2018-08-07
* Time: 11:21
*/
namespace zhimiao;
class Data {
private static $pdo = null, $redis = null;
/**
* mysql
* @throws Exception
* @return Data\XPDO
*/
public static function pdo() {
if (is_object(self::$pdo)) {
return self::$pdo;
}
try{
self::$pdo = new Data\XPDO(
Config::get('db.dsn'),
Config::get('db.user'),
Config::get('db.password'),
[
Data\XPDO::ATTR_DEFAULT_FETCH_MODE => Data\XPDO::FETCH_NAMED,
Data\XPDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES'utf8mb4';"
]
);
self::$pdo->setAttribute(Data\XPDO::ATTR_STATEMENT_CLASS, ['\zhimiao\Data\XPDOStatement', [self::$pdo]]);
}catch (\Exception $e){
throw new \Exception("数据库链接失败", 1);
}
return self::$pdo;
}
/**
* redis
* @return \Redis
* @throws Exception
*/
public static function redis() {
if (is_object(self::$redis)) {
return self::$redis;
}
try{
# 初始化redis
self::$redis = new \Redis();
self::$redis->connect(Config::get('redis.host'), Config::get('redis.port')); //php客户端设置的ip及端口
self::$redis->auth(Config::get('redis.auth')); //授权
}catch (\Exception $e){
throw new \Exception("缓存链接异常", 1);
}
return self::$redis;
}
}

Comment ( 0 )

Sign in for post a comment

PHP
1
https://gitee.com/zhimiao/frame-php.git
git@gitee.com:zhimiao/frame-php.git
zhimiao
frame-php
frame-php
master

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542