What are the potential pitfalls of using mysqli_connect within a function in PHP?
When using mysqli_connect within a function in PHP, one potential pitfall is that the database connection may not be properly closed after the function execution, leading to resource leaks and potential performance issues. To solve this, it's important to close the database connection after using it within the function to ensure proper resource management.
function getDataFromDatabase() {
$conn = mysqli_connect("localhost", "username", "password", "database");
// Perform database operations
mysqli_close($conn); // Close the database connection
}