https://github.com/phpple/mysql
A PHP Mysql Graceful Library. With Features:sql builder,master/slave,table split,connection persist,etc.
https://github.com/phpple/mysql
Last synced: 5 days ago
JSON representation
A PHP Mysql Graceful Library. With Features:sql builder,master/slave,table split,connection persist,etc.
- Host: GitHub
- URL: https://github.com/phpple/mysql
- Owner: phpple
- License: mit
- Created: 2018-08-27T07:41:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-23T08:58:46.000Z (almost 6 years ago)
- Last Synced: 2025-12-14T17:44:09.090Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
Phpple Mysql
=============
`Phpple Mysql`一个基于PHP语言的Mysql类库,具有使用简单、操作优雅、代码严谨、效率优先等诸多优点。
[](https://packagist.org/packages/phpple/mysql)
[](https://php.net/)
[](https://travis-ci.org/phpple/mysql)
[](https://codecov.io/gh/phpple/mysql)
`Phpple Mysql`提供如下优秀的特性:
* SQL构建器
* yield支持
* 主/从库支持
* 长连接支持
* 分表/分库支持
* psr-4支持
### 使用示例
```php
use Phpple\Mysql\Conf;
use Phpple\Mysql\Sql\SqlBuilder;
use Phpple\Mysql\Db;
// 初始化数据库配置
$confs = [
'db' => [
'demo' => [
'dbname' => 'phpple',
'instance' => 'ip1'
],
],
'instance' => [
'ip1' => [
'host' => '127.0.0.1',
'port' => 3306,
'user' => 'root',
'pass' => '',
'charset' => 'utf8'
],
]
];
Conf::init($confs);
$id = 12030;
// 创建一个Sql构建器
$sqlBuilder = SqlBuilder::withTable('u_user')
->fields('view_num')
->setData([
'@view_num' => '(view_num+1)'
])
->where('id', $id);
// 绑定Sql构建器到Db对象
$db = Db::get('demo')->sqlBuilder($sqlBuilder);
// 获取原始view_num
$viewNum = $db->getSingle();
echo 'before:' . $viewNum . PHP_EOL;
// view_num 自增1
$db->update();
// 重新获取view_num
$newViewnum = $db->getSingle();
echo 'after:' . $newViewnum . PHP_EOL;
```