功能 : 删除数据
参数 : 数组形式的更新数据
条件 : 必须 [ 使用 where() 系列函数设置条件 ]
1 为了更安全地进行更新操作,必须设置更新条件,无条件的更新请使用数据库管理工具完成;
2 关于条件设置操作请查看手册《条件设置》一节;
<?php namespace grace\controller; use grace\grace; use grace\database; class index extends grace{ public function index(){ $updateData = array( 'st_name' => 'update test', 'st_age' => 18, 'st_add_time' => time() ); $table = database::table('students'); $res = $table->where('st_id = ?', array(1))->update($updateData); print_r($res); // rowCount 函数可以获取操作影响的条目数 echo '更新受影响的条目数'. $table->rowCount(); } }
功能 : 具体字段增加或减少指定值
参数 :
1 string $filedName 字段名称2 $addVal 增加或减少的值 ( 减少填写负数 )
条件 : 必须 [ 使用 where() 系列函数设置条件 ]
1 为了更安全地进行更新操作,必须设置更新条件,无条件的更新请使用数据库管理工具完成;
2 关于条件设置操作请查看手册《条件设置》一节;
<?php namespace grace\controller; use grace\grace; use grace\database; class index extends grace{ public function index(){ // 将主键为 2 的一条数据的 sta_age 字段值在原有基础上加 2 $res = database::table('students')->where('st_id = ?', array(1))->field('st_age', 2); // 运行语句 // update grace_students set st_age = st_age + 2 where ( st_id = ? ); print_r($res); } }