maybe_create_table
函数
maybe_create_table ( $table_name, $create_ddl )
- 参数
-
-
(string)
$table_name
Database table name.- Required: 是
-
(string)
$create_ddl
SQL statement to create table.- Required: 是
-
(string)
- 返回值
-
- (bool) True on success or if the table already exists. False on failure.
- 定义位置
-
-
wp-admin/install-helper.php
, line 52
-
wp-admin/install-helper.php
- 引入
- 1.0.0
- 弃用
- –
Creates a table in the database if it doesn’t already exist.
function maybe_create_table( $table_name, $create_ddl ) { global $wpdb; foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) { if ( $table === $table_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( 'SHOW TABLES', 0 ) as $table ) { if ( $table === $table_name ) { return true; } } return false; } endif; if ( ! function_exists( 'maybe_add_column' ) ) : /** * Adds column to database table, if it doesn't already exist. * * @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 $create_ddl SQL statement to add column. * @return bool True on success or if the column already exists. False on failure. */
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。