hongxunpan / db
用于db的连接,例如mysql & redis ...
1.0.2
2022-10-15 07:30 UTC
Requires
- php: >=5.6
Requires (Dev)
- symfony/var-dumper: ^6.0
This package is auto-updated.
Last update: 2024-09-15 11:36:12 UTC
README
包括
- redis
- mysqli
- pdo
安装
composer require hongxunpan/db
使用
redis (\HongXunPan\DB\Redis\Redis)
配置设置
$config = ['host' => '192.168.0.1']; \HongXunPan\DB\Redis\Redis::setConfig($config, 'default');//array $config = [], $connectName = 'default', array $options = []
默认设置
$default = [ 'host' => '127.0.0.1', 'port' => 6379, 'timeout' => 0.0, 'reserved' => null, 'retryInterval' => 0, 'readTimeout' => 0.0 ];
使用
$res = \HongXunPan\DB\Redis\Redis::connection()->set('test', 'test'); $res = \HongXunPan\DB\Redis\Redis::connection('xxx')->getConnection()->set('test', 'test1'); $res = \HongXunPan\DB\Redis\Redis::connection('aaa')->incr('testIncr'); /** \Redis $res */ var_dump($res);
mysqli
配置设置
$config = [ 'host' => '192.168.65.2', 'port' => 3306, 'username' => 'default', 'password' => 'secret', 'database' => '', ]; \HongXunPan\DB\Mysql\Mysqli\Mysqli::setConfig($config, 'default');
使用
/** @var PDO $res */ $res = \HongXunPan\DB\Mysql\Mysqli\Mysqli::connection('default')->getConnection(); $res = \HongXunPan\DB\Mysql\Mysqli\Mysqli::getConnection(); var_dump($res);
pdo
配置设置
$config = [ 'host' => '192.168.65.2', 'port' => 3306, 'username' => 'default', 'password' => 'secret', ]; \HongXunPan\DB\Mysql\Pdo\Pdo::setConfig($config, 'default');
使用
$res = \HongXunPan\DB\Mysql\Pdo\Pdo::connection('default')->getConnection(); $res = \HongXunPan\DB\Mysql\Pdo\Pdo::getConnection('default')
更新日志
1.0.2
2022-10-15 修复 connection() 文档提示1.0.1
2022-10-13 修复单例扩展错误1.0.0
2022-10-13 第1版,包括 redis & mysqli & pdo