What are best practices for splitting large SQL files into smaller chunks for easier processing in PHP?

When dealing with large SQL files in PHP, it is best practice to split them into smaller chunks for easier processing. One way to achieve this is by reading the SQL file line by line and executing queries in batches. This can help prevent memory issues and improve performance.

// Read the SQL file line by line
$filename = 'large_sql_file.sql';
$handle = fopen($filename, "r");

if ($handle) {
    $query = '';
    while (($line = fgets($handle)) !== false) {
        $query .= $line;
        
        // Execute queries in batches
        if (substr(trim($line), -1) == ';') {
            // Execute query
            $pdo->exec($query);
            $query = '';
        }
    }

    fclose($handle);
} else {
    echo "Error opening file.";
}