Skip to content

Commit

Permalink
Update Table::exists() to check information schema (#166)
Browse files Browse the repository at this point in the history
Prefer `SELECT` over `SHOW TABLES LIKE`

Fixes #165.
  • Loading branch information
Khadreal authored Sep 19, 2024
1 parent 9c4d1fe commit 8c4fcd9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Database/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,9 @@ public function exists() {
return false;
}

// Query statement
$query = "SHOW TABLES LIKE %s";
$like = $db->esc_like( $this->table_name );
$prepared = $db->prepare( $query, $like );
// Query statement to check if table exists.
$query = "SELECT table_name FROM information_schema.TABLES WHERE table_name = %s LIMIT 1";
$prepared = $db->prepare( $query, $this->table_name );
$result = $db->get_var( $prepared );

// Does the table exist?
Expand Down

0 comments on commit 8c4fcd9

Please # to comment.