maybe_drop_column() - WordPress 函数参考中文文档

返回介绍

maybe_drop_column()

发布于 2017-09-11 字数1705 浏览 814 评论 0

maybe_drop_column( string $table_name,  string $column_name,  string $drop_ddl )

Drop column from database table, if it exists.


描述


参数

$table_name

(string)
(Required)
Table name

$column_name

(string)
(Required)
Column name

$drop_ddl

(string)
(Required)
SQL statement to drop column.


返回值

(bool) False on failure, true on success or doesn’t exist.


源代码

File: wp-admin/install-helper.php

function maybe_drop_column($table_name, $column_name, $drop_ddl) {
	global $wpdb;
	foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
		if ($column == $column_name) {

			// Found it, so try to drop it.
			$wpdb->query($drop_ddl);

			// We cannot directly tell that whether this succeeded!
			foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
				if ($column == $column_name) {
					return false;
				}
			}
		}
	}
	// Else didn't find it.
	return true;
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

  • wp-includes/wp-db.php:
    wpdb::get_col()
  • wp-includes/wp-db.php:
    wpdb::query()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!