Skip to content

HongXunPan/db-connection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

db-connection DB 连接器封装包

including :

  • redis
  • mysqli
  • pdo

install

composer require hongxunpan/db

usage

redis (\HongXunPan\DB\Redis\Redis)

set config

$config = ['host' => '192.168.0.1'];
\HongXunPan\DB\Redis\Redis::setConfig($config, 'default');//array $config = [], $connectName = 'default', array $options = []

default setting

$default = [
    'host' => '127.0.0.1',
    'port' => 6379,
    'timeout' => 0.0,
    'reserved' => null,
    'retryInterval' => 0,
    'readTimeout' => 0.0
];

using

$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

set config

$config = [
    'host' => '192.168.65.2',
    'port' => 3306,
    'username' => 'default',
    'password' => 'secret',
    'database' => '',
];

\HongXunPan\DB\Mysql\Mysqli\Mysqli::setConfig($config, 'default');

using

/** @var PDO $res */
$res = \HongXunPan\DB\Mysql\Mysqli\Mysqli::connection('default')->getConnection();
$res = \HongXunPan\DB\Mysql\Mysqli\Mysqli::getConnection();
var_dump($res);

pdo

set config

$config = [
    'host' => '192.168.65.2',
    'port' => 3306,
    'username' => 'default',
    'password' => 'secret',
];

\HongXunPan\DB\Mysql\Pdo\Pdo::setConfig($config, 'default');

using

$res = \HongXunPan\DB\Mysql\Pdo\Pdo::connection('default')->getConnection();
$res = \HongXunPan\DB\Mysql\Pdo\Pdo::getConnection('default')

update log

  • 1.0.2 2022-10-15 fix connection() doc tips
  • 1.0.1 2022-10-13 fix singleton extends bug
  • 1.0.0 2022-10-13 version1, include redis & mysqli & pdo

About

connections for db, such as mysql & redis ...

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages