I am using MySQL temp tables to generate reports. Lets say I am generating 4 reports for 4 students and each report has to be put into a separate tab in a single page of different pages. Now , MySQL temp tables will be dropped as soon as i switch from MySQL DB to Drupal DB.

I assume that, to display anything on to the screen, I will have to break the connection to MYsql DB and connect back to Drupal DB. This is causing problems as my temp tables get destroyed when the user goes to different reports in different pages or different tabs.

A rough idea of execution
1. Connect to mYsql
2. Do alll the processing and store it in a temp table(this contains data of 4 students - each of which has to be displayed in a separate tab in a page or different page for each student - each page contains links to all other student reports)
3.When the user clicks a link - i have to display the data - i read the data of the particular student and disconnect from the MySQL DB(here i loose the temp tables and data of all other students)

I cannot store the table or cache then or use session variables - because the reports are too huge. Currently i dump all the data into files and get it back when the user wants to see it - but this file read takes a lot of time (the data is presented in a table and everytime i read the data i have to explode it to an array and pass it to drupals theme_table)

Is there a better and faster way of doing this? might be if i can display the report without breaking the connection to MySQL?

Thanks