Form
5 years ago
Frontend
5 years ago
Gateways
5 years ago
ArrayDataSet.php
5 years ago
Hooks.php
5 years ago
Html.php
4 years ago
Table.php
5 years ago
Utils.php
6 years ago
Table.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Helpers; |
| 4 | |
| 5 | /** |
| 6 | * Class Table |
| 7 | * @package Give\Helpers |
| 8 | * |
| 9 | * @since 2.9.0 |
| 10 | */ |
| 11 | class Table { |
| 12 | /** |
| 13 | * Get table name. |
| 14 | * |
| 15 | * @since 2.9.0 |
| 16 | * |
| 17 | * @param $tableName |
| 18 | * |
| 19 | * @return string |
| 20 | */ |
| 21 | public static function prefixTableName( $tableName ) { |
| 22 | global $wpdb; |
| 23 | |
| 24 | return "{$wpdb->prefix}{$tableName}"; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Check if the given table exists |
| 29 | * |
| 30 | * @since 2.9.0 |
| 31 | * @access public |
| 32 | * |
| 33 | * @param $tableName |
| 34 | * |
| 35 | * @return bool If the table name exists. |
| 36 | */ |
| 37 | public static function tableExists( $tableName ) { |
| 38 | global $wpdb; |
| 39 | |
| 40 | return (bool) $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $tableName ) ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Checks whether column exists in a table or not. |
| 45 | * |
| 46 | * @since 2.9.0 |
| 47 | * |
| 48 | * @param $columnName |
| 49 | * @param $tableName |
| 50 | * |
| 51 | * @return bool |
| 52 | */ |
| 53 | public static function doesColumnExist( $tableName, $columnName ) { |
| 54 | global $wpdb; |
| 55 | |
| 56 | return (bool) $wpdb->get_results( |
| 57 | $wpdb->prepare( |
| 58 | 'SELECT * FROM INFORMATION_SCHEMA.COLUMNS |
| 59 | WHERE TABLE_SCHEMA = %s |
| 60 | AND TABLE_NAME = %s |
| 61 | AND COLUMN_NAME = %s ', |
| 62 | DB_NAME, |
| 63 | $tableName, |
| 64 | $columnName |
| 65 | ) |
| 66 | ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 |