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
3fcac774
Commit
3fcac774
authored
Dec 05, 2014
by
Lynnworld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update db-dao.md
parent
878d4abf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
12 deletions
+20
-12
db-dao.md
docs/guide-zh-CN/db-dao.md
+20
-12
No files found.
docs/guide-zh-CN/db-dao.md
View file @
3fcac774
...
...
@@ -433,31 +433,39 @@ $rows = $db->useMaster(function ($db) {
###操作数据库模式
获得模式信息
####
获得模式信息
如下获得
[
[yii\db\Schema
]
]实例:
你可以通过 [[yii\db\Schema]]实例来获取Schema信息:
```
php
$schema = $connection->getSchema();
```
该实例包括一系列方法来检索数据库多方面的信息:
```
php
$tables = $schema->getTableNames();
完整参考请核对
[
[yii\db\Schema
]
]。
```
更多信息请参考[[yii\db\Schema]]
修改模式
####
修改模式
除了基础的 SQL 查询,[[yii\db\Command]]还包括一系列方法来修改数据库模式:
createTable, renameTable, dropTable, truncateTable
addColumn, renameColumn, dropColumn, alterColumn
addPrimaryKey, dropPrimaryKey
addForeignKey, dropForeignKey
createIndex, dropIndex
如下使用它们:
- 创建/重命名/删除/清空表
- 增加/重命名/删除/修改字段
- 增加/删除主键
- 增加/删除外键
- 创建/删除索引
使用示例:
// 新建表
```
php
// 创建表
$connection->createCommand()->createTable('post',
[
'id' => 'pk',
'title' => 'string',
'text' => 'text',
]);
完整参考请核对
[
[yii\db\Command
]
].
```
完整参考请查看
[
[yii\db\Command
]
].
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