class-arr.php
2 years ago
class-attachment.php
2 years ago
class-conditional.php
2 years ago
class-db.php
2 years ago
class-html.php
2 years ago
class-param.php
2 years ago
class-str.php
2 years ago
class-url.php
2 years ago
class-wordpress.php
2 years ago
index.php
2 years ago
class-db.php
68 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The database helpers. |
| 4 | * |
| 5 | * @since 1.0.0 |
| 6 | * @package MyThemeShop |
| 7 | * @subpackage MyThemeShop\Helpers |
| 8 | * @author MyThemeShop <admin@mythemeshop.com> |
| 9 | */ |
| 10 | |
| 11 | namespace MyThemeShop\Helpers; |
| 12 | |
| 13 | use MyThemeShop\Database\Database; |
| 14 | |
| 15 | /** |
| 16 | * DB class. |
| 17 | */ |
| 18 | class DB { |
| 19 | |
| 20 | /** |
| 21 | * Retrieve a Database instance by table name. |
| 22 | * |
| 23 | * @param string $table_name A Database instance id. |
| 24 | * |
| 25 | * @return Database Database object instance. |
| 26 | */ |
| 27 | public static function query_builder( $table_name ) { |
| 28 | return Database::table( $table_name ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Check if table exists in db or not. |
| 33 | * |
| 34 | * @param string $table_name Table name to check for existance. |
| 35 | * |
| 36 | * @return bool |
| 37 | */ |
| 38 | public static function check_table_exists( $table_name ) { |
| 39 | global $wpdb; |
| 40 | |
| 41 | if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->prefix . $table_name ) ) ) === $wpdb->prefix . $table_name ) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Check if table has more rows than X. |
| 50 | * |
| 51 | * @since 1.1.16 |
| 52 | * |
| 53 | * @param string $table_name Table name to check. |
| 54 | * @param int $limit Number of rows to check against. |
| 55 | * |
| 56 | * @return bool |
| 57 | */ |
| 58 | public static function table_size_exceeds( $table_name, $limit ) { |
| 59 | global $wpdb; |
| 60 | |
| 61 | $check_table = $wpdb->query( "SELECT 1 FROM {$table_name} LIMIT {$limit}, 1" ); |
| 62 | |
| 63 | return ! empty( $check_table ); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | } |
| 68 |