增删改操作


一、新增数据

插入一条

$insert_id = $db->table('user')->insert([
    'nickname' => 'tommy',
    'avatar' => 'b644.jpg',
    'sex' => 1,
    'crated' => NOW_TIME,
]);

插入多条

/*$ret = $db->table('user')->insertAll([
    [
        'nickname' => 'davy',
        'avatar' => '3498305.jpg',
        'created' => NOW_TIME
    ],
    [
        'nickname' => 'laden',
        'avatar' => '3498305.jpg',
        'created' => NOW_TIME
    ],
    [
        'nickname' => 'lucy',
        'avatar' => '3498305.jpg',
        'created' => NOW_TIME
    ],
]);

二、更新数据

$ret = $db
    ->table('user')
    ->where(['nickname' => 'timor'])
    ->update([
        'avatar' => 'b344.jpg'
    ]);
if ($ret === false) {
    return false;
}
return true;

三、自增、自减

$db->table('user')->where(3498305)->inc('balance'); //加1
$db->table('user')->where(3498305)->inc('balance', 5); //加5

$db->table('user')->where(3498305)->dec('balance'); //减1
$db->table('user')->where(3498305)->dec('balance', 5); //减5

四、删除数据

$ret = $db->table('user')->where(6)->delete(); //返回受影响行数
if ($ret > 0) {
    return true;
}
return false;