WordPress开发者和主题制作者的搜索引擎



maybe_create_table ›

Since1.0.0
已弃用n/a
maybe_create_table ( $table_name, $create_ddl )
参数: (2)
  • (string) $table_name Database table name.
    Required: Yes
  • (string) $create_ddl Create database table SQL.
    Required: Yes
返回:
  • (bool) False on error, true if already exists or success.
定义在:
文档:

Create database table, 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' ) ) :