数据模型提供了5种数据更新的方法,下面以实例说明:
§ 使用数组更新
$model = loader::model('guestbook');
$where = "gid=1";
$data = array('title'=>'这是一条测试留言', 'content'=>'这是留言的内容');
$result = $model->update($data, $where);
$data数组的键是字段名,值是字段值。
§ 使用对象更新
$model = loader::model('guestbook');
$model->gid = 1;
$model->title = '这是一条测试留言';
$model->content = '这是留言的内容';
$result = $model->update();
$model定义的属性是字段名,属性值是字段值。
§ 字段更新
$model = loader::model('guestbook');
$where = "gid=1";
$result = $model->set_field('title', '这是一条测试留言', $where);
§ 字段值加一
$model = loader::model('guestbook');
$where = "gid=1";
$result = $model->set_inc('pv', $where);
§ 字段值减一
$model = loader::model('guestbook');
$where = "gid=1";
$result = $model->set_dec('pv', $where);
注:$where 支持 字符串和数组两种赋值方式,如下两种格式都是正确的:
//字符串赋值
$where = "gid=1";
//数组赋值
$where['gid'] = 1;