我们在对最土程序进行二次开发的过程中。我们常常需要对数据库进行操作.最土程序的数据库操作方式还不少。我们将陆续总结最土程序的一些常见的数据库操作方式.
1:如何取得最土数据库中一条数据。使用LimitQuery()
$res = DB::LimitQuery('subscribe',array('condition'=>array('email'=>$email),'one'=>true));
2:最土程序如何进行数据库插入数据
$table = new Table('subscribe', array(
'email' => $email,
'city_id' => $city_id,
'secret' => $secret,
));
return $table->insert(array('email', 'city_id', 'secret'));
3:检索一行内容
$field = strpos($email, '@') ? 'email' : 'username';
$zuituuser = DB::GetTableRow('user', array(
$field => $email,
'password' => $password,
));
4:通过某个值检索一行数据
return Table::Fetch('user', $email, 'email');
5:修改数据库字段某个值
$table = new Table('user', $newuser);
$table->SetPk('id', $user_id);
if ($table->password) {
$plainpass = $table->password;
$table->password = self::GenPassword($table->password);
}
return $table->Update( array_keys($newuser) );
6:如何统计数据库中某些数据的条数
$now_count = Table::Count('order', array(
'user_id' => $login_user_id,
'team_id' => $id,
'state' => 'pay',
), 'quantity');
7:如何修改数据库中某个字段的值
Table::UpdateCache('order',$table->id,array('order_sn'=>get_order_sn()));
8:最土中如何检索某个字段的值
$cond = array('zone'=>'city');
$info = DB::LimitQuery('category', array(
'condition' => $cond,
'order' => 'ORDER BY id DESC',
));
$citys = Utility::GetColumn($info, 'name');
9:最土如何删除一条数据
Table::Delete('article', $id);