溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Fleaphp常見函數(shù)有哪些

發(fā)布時間:2021-08-27 11:31:26 來源:億速云 閱讀:153 作者:小新 欄目:開發(fā)技術(shù)

這篇文章給大家分享的是有關Fleaphp常見函數(shù)有哪些的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

1. FLEA_Db_TableDataGateway::update()用法:

例如:修改一條 uid=22 的記錄, name字段改成"11", pass字段改成"22",就要這樣寫:

$data = array('uid'=>22,'name'=>11,'pass'=>22);
$table->update($data);

2. FLEA_Db_TableDataGateway::updateByConditions()用法:

例如:更新所有 level_ix = 3 的記錄,并且把這些記錄的特定字段(由 $row 確定)都更新為指定的值。

$row = array(
字段 => 字段值
字段 => 字段值
字段 => 字段值
字段 => 字段值
);
$conditions = array('level_ix' => 3);
$table->updateByConditions($conditions, $row);

3. FLEA_Db_TableDataGateway::updateField()用途:更新記錄的指定字段,返回更新的記錄總數(shù)

例如:以查找滿足$conditions的條件,修改其中字段為class_id的值為$targetId.

$sourceId = $_POST['source']; 
$targetId = $_POST['target']; 
$conditions = array('class_id' => $sourceId);
$table->updateField($conditions,'class_id',$targetId);

4. FLEA_Db_TableDataGateway::updateRowset ()用途:更新記錄集(多行記錄)

用法和update ()類似,只不過是修改多條記錄:

例如:

$data =array(array('id'=>'2','name'=>'111','job'=>'111'),array('id'=>'3','name'=>'222','job'=>'222'));
$arr=$this->_test->updateRowset($data);

想必大家能看明白吧...呵呵。。。

一定注意:$data 一定要是二維的,即使用updateRowset ()修改一條記錄也要這樣寫:

$data=array(array('id'=>'2','name'=>'111','job'=>'111'));

說得清不清楚啊?呵呵

5. FLEA_Db_TableDataGateway::create ()用途:插入一條新記錄,返回新記錄的主鍵值

例如:

$data = array(array('uid'=>22,'name'=>11,'pass'=>22),array('uid'=>23,'name'=>12,'pass'=>23));
$table->create($data);

6. FLEA_Db_TableDataGateway::createRowset()插入多行記錄,返回包含所有新記錄主鍵值的數(shù)組

例如:

$data = array(array('uid'=>22,'name'=>11,'pass'=>22),array('uid'=>23,'name'=>12,'pass'=>23));
$table->createRowset($data);

7. FLEA_Db_TableDataGateway::remove () 刪除一條記錄,條件必須為主鍵

例如:

remove(array("id"=>"2"));

8. FLEA_Db_TableDataGateway::removeByConditions ()看名知義,當然是刪除符合條件的記錄嘍

正常情況下和remove()的條件可以通和,如果對有多個主鍵的表進行刪除操作:

conditions = array(
'主鍵1' => xxx,
'主鍵2' => yyy,
'主鍵3' => zzz,
)
$table->removeByConditions($conditions);

另注意一點:如果某個表有多個主鍵的話,那么它所對應的Model中的 $primaryKey 只能設置為一個最常用的主鍵,不能設置為一個數(shù)組

9. & FLEA_Db_TableDataGateway::findBySql ()用途:直接使用 sql 語句獲取記錄

例如:

$arr=$this->_test->findBySql('SELECT * FROM newtable');

10. FLEA_Db_TableDataGateway::decrField ()用途:減小符合條件的記錄的指定字段的值,返回更新的記錄總數(shù) (該操作不會引發(fā)任何事件,也不會處理關聯(lián)數(shù)據(jù))。

例如:

$arr=$this->_test->decrField(array('id'=>'3'),'prize',$decr = 2);

注意:$decr默認值為1,數(shù)字2是本人自己改的,當然你也可以改為34568了,改幾就減幾,明白了吧。。。

11. FLEA_Rbac_UsersManager::updatePasswordById ()用途:直接更新密碼

例如:把ID為1的密碼設為00000

$arr=$this->_student->updatePasswordById ('1','000000');

注意:前提是數(shù)據(jù)庫中一定要有叫做Password的字段;修改后的密碼是加密的。

12. FLEA_Rbac_UsersManager::checkPassword ()用途:檢查密碼的明文和密文是否符合

例如:

$user = $usersManager->findByUsername('andy');
$usersManager->checkPassword('000000', $user[$usersManager->passwordField]))

13. FLEA_Rbac_UsersManager::encodePassword ()用途:將密碼明文轉(zhuǎn)換為密文

例如:

$user = $this->_student->findByUsername('andy');
$arr=$this->_student->encodePassword($user[$this->_student->passwordField]);
$this->_student->updatePassword($user[username],$arr);

注意:前提是數(shù)據(jù)庫中一定要有叫做Password的字段;

14. FLEA_Rbac_UsersManager::updatePasswordById ()用途:直接更新密碼

這個我不說了啊,我想聰明的你一看例11就會明白了

15. FLEA_Db_TableDataGateway::updateByConditions ()用途:更新符合條件的記錄,成功返回更新的記錄總數(shù)

例如:

$condition=array('id'=>2);
$row=array('name'=>'nicholas');
$this->_test->updateByConditions($condition,$row);

16. FLEA_Db_TableDataGateway::updateField () 用途:更新記錄的指定字段,返回更新的記錄總數(shù) 該操作不會引發(fā)任何事件,也不會處理關聯(lián)數(shù)據(jù)。

例如:修改id為2的記錄,把字段為name的值修改為vin就要這么寫:

$condition=array('id'=>2);
$this->_test->updateField($condition,'name','vin');

17. FLEA_Db_TableDataGateway::incrField () 用途:增加符合條件的記錄的指定字段的值,返回更新的記錄總數(shù)

例如:這個也不說,去看例10吧,但要注意,例10是減,這個是加,嘿嘿。。。

18. FLEA_Db_TableDataGateway::replaceRowset () 用途:替換記錄集(多行數(shù)據(jù)),返回記錄集的主鍵字段值,失敗返回 false

$condition=array(array('id'=>2,'name'=>nicholas,'job'=>good));
$this->_test->replaceRowset($condition);

注意:

① 假設表中有id,name,job,prize等,如果在$condition中沒寫prize字段,會就默認插入空,原有的數(shù)據(jù)會被清除,如不注意,也許會丟失數(shù)據(jù)
② $condition一定是二維的

19. FLEA_Db_TableDataGateway::removeAll ()用途:刪除所有記錄,用時要謹慎

例如:

$this->_test->removeAll ();

20. FLEA_Db_TableDataGateway::removeAllWithLinks ()用途:刪除所有記錄及關聯(lián)的數(shù)據(jù)

注意:這個更加要慎用,所有與這個表有關聯(lián)的表數(shù)據(jù)都將被刪除,何謂有關聯(lián),也就是說,此表中的某個字段可能是另外一個表中的外鍵,此謂之有關聯(lián)。

例如:

在MODEL中一個叫做com的表關聯(lián)了一個叫做student的表,com表中的uid是student表中的外鍵,那么我們就說這兩個表關聯(lián)起來了,是用下面的方法關聯(lián)起來的

class Model_com extends FLEA_Db_TableDataGateway
{
var $tableName = 'newtable';
var $primaryKey = 'uid';
var $hasOne=array('tableClass' => 'Model_student',
'foreignKey' => 'uid',
'mappingName'=>'jobs');
}

這時,我們執(zhí)行下面的語句:

$this->_test =& FLEA::getSingleton('Model_com'); 
$this->_test->removeAllWithLinks();

感謝各位的閱讀!關于“Fleaphp常見函數(shù)有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI