ligan / easy-db
This is a simple MySQL database operation package, support connection pool and disconnection reconnection
v1.1
2021-11-26 08:38 UTC
Requires
- php: >=7.1
- ext-swoole: >=4.4
- swoole/ide-helper: ^4.8
Requires (Dev)
Suggests
- swoole/library: Required to use database, and the swoole version is less than 4.4.17
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