ligan/easy-db

This is a simple MySQL database operation package, support connection pool and disconnection reconnection

Maintainers

Details

gitee.com/ligan0404/easy-db

Installs: 46

Dependents: 1

Suggesters: 0

Security: 0

Type:1

v1.1 2021-11-26 08:38 UTC

This package is auto-updated.

Last update: 2024-10-26 15:49:51 UTC


README

这是一个简单的mysql数据库,redis操作包,支持连接池以及断线重连,依赖 Swoole ConnectionPool PDOPool/RedisPool,Medoo框架语法。

This is a simple MySQL database operation package, support connection pool and disconnection reconnection

安装

composer require ligan/easy-db

数据库使用

配置

$config = array(
    'host'       => "127.0.0.1",
    'port'       => 3306,
    'database'   => 'tpshop',
    'username'   => 'root',
    'password'   => '123456',
    'charset'    => 'utf8mb4',
    'unixSocket' => null,
    'options'    => [
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ],
    'size'       => 10
);

$db = new \EasyDB\Db\EasyPdo($config,"master");

查询

$db = new \EasyDB\Db\EasyPdo(`配置`,"master");
$db->get("test", "*");

新增

$db = new \EasyDB\Db\EasyPdo(`配置`,"master");
$db->insert("test", ["name" => "test"]);

编辑

$db = new \EasyDB\Db\EasyPdo(`配置`,"master");
$db->update("test", ["name" => "test2"], ["id" => 1]);

删除

$db = new \EasyDB\Db\EasyPdo(`配置`,"master");
$db->delete("test", ["id" => 1]);

具体更多的操作方法可参考官方文档:https://medoo.lvtao.net/

Redis使用

配置

$conf  = [
    'host'     => 'localhost',
    'port'     => 6379,
    'auth'     => '7GNR8pI5LOlh',
    'db_index' => 15,
    'time_out' => 3,
    'size'     => 1,
];
$redis = new \EasyDB\RedisDb\EasyRedis($conf, "master");

set

$redis = new \EasyDB\RedisDb\EasyRedis(`配置`, "master");
$redis->set('key',"test");

get

$redis = new \EasyDB\RedisDb\EasyRedis(`配置`, "master");
$redis->get('key');

具体更多的操作方法可参考官方文档:http://redis.cn/commands.html