Commit 3a232743 by Alexander Makarov

Added info about table prefix syntax to the guide

parent 663d3fed
......@@ -173,6 +173,29 @@ $rowCount = $connection->createCommand($sql)->queryScalar();
In the code above `[[X]]` will be converted to properly quoted column name while `{{Y}}` will be converted to properly
quoted table name.
For table names there's a special variant `{{%Y}}` that allows you to automatically appending table prefix if it is set:
```php
$sql = "SELECT COUNT([[$column]]) FROM {{%$table}}";
$rowCount = $connection->createCommand($sql)->queryScalar();
```
The code above will result in selecting from `tbl_table` if you have table prefix configured like the following in your
config file:
```php
return [
// ...
'components' => [
// ...
'db' => [
// ...
'tablePrefix' => 'tbl_',
],
],
];
```
The alternative is to quote table and column names manually using [[yii\db\Connection::quoteTableName()]] and
[[yii\db\Connection::quoteColumnName()]]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment