make_db_current()
云策文档标注
概述
make_db_current() 函数用于更新数据库表以匹配最新定义的架构,可更新所有表或指定表集。
关键要点
- 函数默认更新所有表到最新架构,但可通过参数指定表集。
- 参数 $tables 为可选字符串,默认值为 'all',用于控制更新的表范围。
- 内部调用 dbDelta() 执行数据库修改,并输出变更信息。
- 该函数位于 wp-admin/includes/upgrade.php 文件中,自 WordPress 1.5.0 版本引入。
代码示例
function make_db_current( $tables = 'all' ) {
$alterations = dbDelta( $tables );
echo "n";
foreach ( $alterations as $alteration ) {
echo "$alterationn";
}
echo "n";
}注意事项
- 使用前需确保 wp_get_db_schema() 定义了正确的架构。
- 输出变更信息可能影响页面显示,建议在后台或命令行环境中使用。
原文内容
Updates the database tables to a new schema.
Description
By default, updates all the tables to use the latest defined schema, but can also be used to update a specific set of tables in wp_get_db_schema() .
Parameters
$tablesstringoptional-
Which set of tables to update. Default is
'all'.
Source
function make_db_current( $tables = 'all' ) {
$alterations = dbDelta( $tables );
echo "<ol>n";
foreach ( $alterations as $alteration ) {
echo "<li>$alteration</li>n";
}
echo "</ol>n";
}
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |