Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
96184c2c
Commit
96184c2c
authored
Jul 03, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added docs about DB table and column quoting
parent
33285c53
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
database-basics.md
docs/guide/database-basics.md
+24
-1
No files found.
docs/guide/database-basics.md
View file @
96184c2c
...
@@ -105,7 +105,7 @@ $command = $connection->createCommand('UPDATE tbl_post SET status=1 WHERE id=1')
...
@@ -105,7 +105,7 @@ $command = $connection->createCommand('UPDATE tbl_post SET status=1 WHERE id=1')
$command
->
execute
();
$command
->
execute
();
```
```
Alternatively the following syntax is possible:
Alternatively the following syntax
that takes care of proper table and column names quoting
is possible:
```
php
```
php
// INSERT
// INSERT
...
@@ -130,6 +130,29 @@ $connection->createCommand()->update('tbl_user', array(
...
@@ -130,6 +130,29 @@ $connection->createCommand()->update('tbl_user', array(
$connection
->
createCommand
()
->
delete
(
'tbl_user'
,
'status = 0'
)
->
execute
();
$connection
->
createCommand
()
->
delete
(
'tbl_user'
,
'status = 0'
)
->
execute
();
```
```
Quoting table and column names
------------------------------
If you are building query string dynamically make sure you're properly quoting table and column names using
[
[\yii\db\Connection::quoteTableName()]] and [[\yii\db\Connection::quoteColumnName()]
]:
```php
$column = $connection->quoteColumnName($column);
$table = $connection->quoteTableName($table);
$sql = "SELECT COUNT($column) FROM $table";
$rowCount = $connection->createCommand($sql)->queryScalar();
```
Alternatively you can use special syntax when writing SQL:
```
php
$sql = "SELECT COUNT({{$column}}) FROM
[
[$table
]
]";
$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.
Prepared statements
Prepared statements
-------------------
-------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment