maybe_create_table()
最后更新于:2021-11-27 14:41:53
maybe_create_table( string$table_name, string$create_ddl)Creates a table in the database, if it doesn’t already exist.
参数
- $table_name
-
(string) (Required) Database table name.
- $create_ddl
-
(string) (Required) SQL statement to create table.
响应
(bool) True on success or if the table already exists. False on failure.
源文件
文件: gc-admin/includes/upgrade.php
function maybe_create_table( $table_name, $create_ddl ) {
global $gcdb;
$query = $gcdb->prepare( 'SHOW TABLES LIKE %s', $gcdb->esc_like( $table_name ) );
if ( $gcdb->get_var( $query ) === $table_name ) {
return true;
}
// Didn't find it, so try to create it.
$gcdb->query( $create_ddl );
// We cannot directly tell that whether this succeeded!
if ( $gcdb->get_var( $query ) === $table_name ) {
return true;
}
return false;
}