Is it a good practice to create SQL statements in a separate PHP file and pass them to another PHP file for execution?

It is generally a good practice to separate SQL statements from the rest of your PHP code for better organization and readability. By creating SQL statements in a separate PHP file, you can easily manage and maintain your queries without cluttering your main PHP files. You can then include or require this file in other PHP files where you need to execute these queries.

// sql_queries.php
<?php
$sql_query = "SELECT * FROM users";
```

```php
// execute_query.php
<?php
require 'sql_queries.php';

// Connect to the database and execute the SQL query
$conn = new mysqli($servername, $username, $password, $dbname);
$result = $conn->query($sql_query);

// Process the result
if ($result->num_rows > 0) {
    // Output data
    while($row = $result->fetch_assoc()) {
        echo "Name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();