主頁(yè) > 知識(shí)庫(kù) > bindParam和bindValue的區(qū)別以及在Yii2中的使用詳解

bindParam和bindValue的區(qū)別以及在Yii2中的使用詳解

熱門(mén)標(biāo)簽:阿里云 服務(wù)器配置 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 銀行業(yè)務(wù) 團(tuán)購(gòu)網(wǎng)站 電子圍欄

bindParam() 和 bindValue() 非常相似。唯一的區(qū)別就是前者使用一個(gè) PHP 變量綁定參數(shù), 而后者使用一個(gè)值。對(duì)于那些內(nèi)存中的大數(shù)據(jù)塊參數(shù),處于性能的考慮,應(yīng)優(yōu)先使用前者。

根據(jù)id查詢一條數(shù)據(jù),并對(duì)id進(jìn)行過(guò)濾:

$id = 1;
$result = Yii::$app->db->createCommand("select * from product where id=:id")->bindParam(":id",$id,\PDO::PARAM_INT)->queryAll();
$result = Yii::$app->db->createCommand("select * from product where id=:id")->bindParam(":id",$id,\PDO::PARAM_STR)->queryAll();

更新一條數(shù)據(jù):

$id = 1;
$name = 'xiaoming';
$result = Yii::$app->db->createCommand("update product set name=:name where id=:id")->bindParam(':id',$id,\PDO::PARAM_INT)->bindParam(':name',$name,\PDO::PARAM_INT)->execute();

以下寫(xiě)法在會(huì)報(bào)錯(cuò)

$result = Yii::$app->db->createCommand()->delete('product',['name'=>':value'],'id=:id')->bindValue(':id',1,\PDO::PARAM_INT)->bindParam(':value',$user,\PDO::PARAM_INT)->execute();

以上這篇bindParam和bindValue的區(qū)別以及在Yii2中的使用詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PHP PDOStatement對(duì)象bindpram()、bindvalue()和bindcolumn之間的區(qū)別

標(biāo)簽:萍鄉(xiāng) 大理 蚌埠 衢州 棗莊 衡水 江蘇 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《bindParam和bindValue的區(qū)別以及在Yii2中的使用詳解》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266