maybe_add_column
函数
maybe_add_column ( $table_name, $column_name, $create_ddl )
- 参数
-
-
(string)
$table_name
Database table name.- Required: 是
-
(string)
$column_name
Table column name.- Required: 是
-
(string)
$create_ddl
SQL statement to add column.- Required: 是
-
(string)
- 返回值
-
- (bool) True on success or if the column already exists. False on failure.
- 定义位置
-
-
wp-admin/install-helper.php
, line 88
-
wp-admin/install-helper.php
- 引入
- 1.0.0
- 弃用
- –
Adds column to database table, if it doesn’t already exist.
function maybe_add_column( $table_name, $column_name, $create_ddl ) {
global $wpdb;
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return true;
}
}
// Didn't find it, so try to create it.
$wpdb->query( $create_ddl );
// We cannot directly tell that whether this succeeded!
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return true;
}
}
return false;
}
endif;
/**
* Drops column from database table, if it exists.
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table_name Database table name.
* @param string $column_name Table column name.
* @param string $drop_ddl SQL statement to drop column.
* @return bool True on success or if the column doesn't exist. False on failure.
*/
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。