| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Helpers; |
| 4 |
|
| 5 |
use wpdb; |
| 6 |
|
| 7 |
/** |
| 8 |
* A helper object for the wpdb. |
| 9 |
*/ |
| 10 |
class Wpdb_Helper { |
| 11 |
|
| 12 |
/** |
| 13 |
* The WordPress database instance. |
| 14 |
* |
| 15 |
* @var wpdb |
| 16 |
*/ |
| 17 |
private $wpdb; |
| 18 |
|
| 19 |
/** |
| 20 |
* Constructs a Wpdb_Helper instance. |
| 21 |
* |
| 22 |
* @param param wpdb $wpdb The WordPress database instance. |
| 23 |
*/ |
| 24 |
public function __construct( wpdb $wpdb ) { |
| 25 |
$this->wpdb = $wpdb; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Check if table exists. |
| 30 |
* |
| 31 |
* @param string $table The table to be checked. |
| 32 |
* |
| 33 |
* @return bool Whether the table exists. |
| 34 |
*/ |
| 35 |
public function table_exists( $table ) { |
| 36 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. |
| 37 |
$table_exists = $this->wpdb->get_var( "SHOW TABLES LIKE '{$table}'" ); |
| 38 |
if ( is_wp_error( $table_exists ) || is_null( $table_exists ) ) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
return true; |
| 43 |
} |
| 44 |
} |
| 45 |
|