octicon-rss(16/)
You've already forked yii2
mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 02:13:17 +08:00
Merge pull request #6960 from alexbs/patch-1
Update db-dao.md
This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
octicon-diff(16/tw-mr-1) 1 changed files with 4 additions and 4 deletions
@@ -190,8 +190,8 @@ executing it multiple times with different parameters. For example,
|
|||||||
```php
|
```php
|
||||||
$command = $db->createCommand('SELECT * FROM post WHERE id=:id');
|
$command = $db->createCommand('SELECT * FROM post WHERE id=:id');
|
||||||
|
|
||||||
$post1 = $command->bindValue(':id', 1)->queryRow();
|
$post1 = $command->bindValue(':id', 1)->queryOne();
|
||||||
$post2 = $command->bindValue(':id', 2)->queryRow();
|
$post2 = $command->bindValue(':id', 2)->queryOne();
|
||||||
```
|
```
|
||||||
|
|
||||||
Because [[yii\db\Command::bindParam()|bindParam()]] supports binding parameters by references, the above code
|
Because [[yii\db\Command::bindParam()|bindParam()]] supports binding parameters by references, the above code
|
||||||
@@ -202,10 +202,10 @@ $command = $db->createCommand('SELECT * FROM post WHERE id=:id')
|
|||||||
->bindParam(':id', $id);
|
->bindParam(':id', $id);
|
||||||
|
|
||||||
$id = 1;
|
$id = 1;
|
||||||
$post1 = $command->queryRow();
|
$post1 = $command->queryOne();
|
||||||
|
|
||||||
$id = 2;
|
$id = 2;
|
||||||
$post2 = $command->queryRow();
|
$post2 = $command->queryOne();
|
||||||
```
|
```
|
||||||
|
|
||||||
Notice that you bind the placeholder to the `$id` variable before the execution, and then change the value of that variable
|
Notice that you bind the placeholder to the `$id` variable before the execution, and then change the value of that variable
|
||||||
|
|||||||
Reference in New Issue
Block a user