phpYii2框架實現(xiàn)數(shù)據(jù)庫的方法
PHP是解釋執(zhí)行的服務器腳本語言,首先php有簡單容易上手的特點。語法和c語言比較象,所以學過c語言的程序員可以很快的熟悉php的開發(fā)。以下是小編為大家搜索整理的phpYii2框架實現(xiàn)數(shù)據(jù)庫的方法,希望能給大家?guī)韼椭?更多精彩內容請及時關注我們應屆畢業(yè)生考試網!
通用:
use yii\db\Query;$query = new Query();
查詢:
Query:
$rows = (new \yii\db\Query()) ->select(['code', 'name', 'population']) ->from('country') ->limit(10) ->all();
Select:
$data = $query->select(['code', 'name'])->from('country')->all();/pic/p>
From:
$query->from('country'); $query->from(['public.country c']); $query->from('public.country c');
Where:
字符串格式,例如:'status=1'
哈希格式,例如: ['status' => 1, 'type' => 2]
操作符格式,例如:['like', 'name', 'test']
andFilterWhere()orFilterWhere()
Active Record (活動記錄,以下簡稱AR)提供了一個面向對象的接口, 用以訪問數(shù)據(jù)庫中的數(shù)據(jù)。一個 AR 類關聯(lián)一張數(shù)據(jù)表, 每個 AR 對象對應表中的一行,對象的屬性(即 AR 的特性Attribute)映射到數(shù)據(jù)行的對應列。 一條活動記錄(AR對象)對應數(shù)據(jù)表的一行,AR對象的屬性則映射該行的相應列。
這里的增刪改都會用到AR對象進行映射操作。
增加
$country->name = 'UK';$country->save();
修改
$country = Customer::findOne($id);$country->email = 'UK';$country->save(); /pic/p>
刪除
$country = Country::findOne($id);$country->delete();
其他
User::find()->all(); /pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/p>
【phpYii2框架實現(xiàn)數(shù)據(jù)庫的方法】相關文章:
PHP框架:CodeIgniter框架備份數(shù)據(jù)庫03-17
講解Java的Spring框架中的AOP實現(xiàn)08-31
實現(xiàn)員工激勵的方法01-31
PHP 中 MySQL 數(shù)據(jù)庫異步查詢實現(xiàn)03-03
java線程池框架解析方法10-04
PHP實現(xiàn)多線程的方法03-19
php頁面緩存實現(xiàn)方法12-13