PHP code example of keenlysoft / database
1. Go to this page and download the library: Download keenlysoft/database 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/ */
keenlysoft / database example snippets
model::find(['id'])->where(['name'=>'keenly'])->one(); #获取一条数据
model::find(['id'])->where(['name'=>'keenly'])->all(); #获取多条数据
$user = new user();
$user->Update($data,$where,flase); #更新数据
# 使用主键值更新
$user = new user($id);
$user->name = 'jack_yang';
$user->save();
$user = new user();
$user->add($data); #添加数据
#使用AR添加 预处理模式
$user = new user();
$user->name = 'jack_yang';
$user->save();
model::find(['id'])->where(['name'=>'keenly'])->all(false) #all()或者 one()参数为FALSE
model::find('id')->where(['name'=>'keenly'])->count(); # 返回结果 int 整数
model::find('id')->where(['name'=>'keenly'])->exist(); #返回结果 bool
model::find('id')->where(['name'=>'keenly'])->exist(); #返回结果 bool
model::find('id')->where(['name'=>'keenly'])->top(10); #返回数组
user::UpdateCounter(['name'=>2],['id'=>2]); ##参数1 字段=>2 or -2 参数2:where 语句
User::SwitchDB('test'); # test 是database 配置里面连接的数据库名称
$user = User::find()->where([])->all();
User::InitDB();