最土團購程序一些常見的數據庫操作


我們在對最土程序進行二次開發的過程中。我們常常需要對數據庫進行操作.最土程序的數據庫操作方式還不少。我們將陸續總結最土程序的一些常見的數據庫操作方式.

     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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM