Created
May 7, 2020 14:09
-
-
Save pixelbart/34d7e814ce1fa080d8a01bcd23c3290c to your computer and use it in GitHub Desktop.
Helper for WordPress database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Helper for WordPress database. | |
* | |
* @author Pixelbart | |
*/ | |
class Database_Helpers | |
{ | |
/** | |
* Checks if a database exists. | |
* | |
* @global $wpdb | |
* | |
* @return bool | |
*/ | |
public static function table_exists( $table_name ) | |
{ | |
global $wpdb; | |
$table_name = sanitize_text_field( $table_name ); | |
if ( $table_name != $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) ) { | |
return false; | |
} | |
return true; | |
} | |
/** | |
* Optimizes a database table. | |
* | |
* @global $wpdb | |
* | |
* @return void | |
*/ | |
public static function table_optimize( $table_name ) | |
{ | |
global $wpdb; | |
$table_name = sanitize_text_field( $table_name ); | |
$wpdb->query( "OPTIMIZE TABLE $table_name" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment