What code should I use where I used db_query()? I want to execute SHOW TABLES in Drupal 8. In Drupal 7, I would use db_query("SHOW TABLES"), which is deprecated in Drupal 8.

What should I use for Drupal 8?
As quick replacement for queries on the database Drupal uses by default, you can use the following code.

use Drupal\Core\Database\Database;

$db = Drupal::database();
$result = $db-&gt;query("SHOW TABLES");


Keep in mind that:


db_query() will not be removed before Drupal 9 goes off; you can still use it, even if it is preferable to refactor your code to be more object oriented
The code I shown should be used in legacy procedural code; when possible, you should consider refactoring it to be object oriented and use Drupal 8 services and Dependency Injection Container