PHP code example of hongxunpan / db

1. Go to this page and download the library: Download hongxunpan/db library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hongxunpan / db example snippets


$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);

$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);

$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')