Is it possible to execute SQL queries in a loop in PHP?

Yes, it is possible to execute SQL queries in a loop in PHP. You can create a loop that iterates over an array of SQL queries and executes each query using a database connection. This can be useful when you need to perform a series of SQL operations in a batch.

// Example array of SQL queries
$sqlQueries = [
    "INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2')",
    "UPDATE table_name SET column1 = 'new_value' WHERE id = 1",
    "DELETE FROM table_name WHERE id = 2"
];

// Connect to the database
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

// Loop through the array of SQL queries and execute each query
foreach ($sqlQueries as $query) {
    $pdo->query($query);
}