How can one ensure that database connections are properly established before executing queries in PHP?

To ensure that database connections are properly established before executing queries in PHP, you can use the try-catch block to catch any potential connection errors and handle them gracefully. This helps in preventing errors from occurring during query execution due to a failed connection.

```php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
```
In this code snippet, we attempt to establish a connection to the database using PDO. If the connection is successful, a message "Connected successfully" is echoed. If there is an error in establishing the connection, the catch block will catch the exception and echo the error message. This ensures that the database connection is properly established before executing queries.