There comes a time for most serious WordPress developers when they are developing a WordPress site but need a separate PHP page which needs to access WordPress variables, functions and classes, but which for some reason cannot be part of the theme or a plugin.
Here’s the coding pattern for that:
<?php
require 'wp-load.php';
/* your totally unique and original code here */
?>
Just make sure that the require statement has the correct relative path to wp-load.php (it’s in the root directory of a WordPress installation).
Because the entire WordPress environment is loaded, you have access to the database via the $wpdb class, and much more.