sevstudio / sev-mysql
php mysql helper
v1.5
2024-12-03 11:31 UTC
Requires
- php: >=7.0
This package is not auto-updated.
Last update: 2025-06-18 12:19:52 UTC
README
介绍
原生mysql操作类,支持多数据库节点(不支持跨库操作),支持断线重连,fmp环境以及cli环境等均适用
软件架构
php版本>=7.0
安装教程
- composer require sevstudio/sev-mysql
使用说明
- 引入数据库操作类
use Sevstudio\SevMysql\Facade as Db;
- 设置数据库连接信息
Db::Config([ 'default' => [ 'host' => '127.0.0.1', 'port' => 3306, 'uid' => 'abc_com', 'pwd' => 'abc_com', 'dbname' => 'abc_com', 'prefix' => 'sev_', 'charset' => 'utf8', 'reconnect' => 1, //断线重连次数 'usebuffer' => true,//默认使用缓存查询 'debug' => false //是否调试模式 ], 'order' => [ 'host' => '192.168.1.10', 'port' => 3306, 'uid' => 'root', 'pwd' => 'root', 'dbname' => 'order', 'prefix' => 'sev_', 'charset' => 'utf8', 'reconnect' => 1, //断线重连次数 'usebuffer' => true,//默认使用缓存查询 'debug' => false //是否调试模式 ] ]);
查询单表所有数据
$data = Db::M()->GetAll('table');
查询单条数据
$data = Db::M()->find('select * from table');
插入单条数据
$lastId = Db::M()->add('table',[ 'name' => '123' ]);
插入多条数据
$lastId = Db::M()->addall('table',[ ['name' => '123'], ['name' => '456'], ]);
更新数据
$rows = Db::M()->update('update #__table set `name`="666" where id=1'); $rows = Db::M()->savemin('table',[ 'name' => '李四' ],'id=2');
删除数据
$rows = Db::M()->excute('delte from #__table where id=1');
事务操作
Db::M()->begin()
,Db::M()->done()
,Db::M()->back()
切换数据库
查询order库的agent_order表`Db::M('order')->Get('agent_order',1)`
更多功能期待你的发现^_^