开发者

Get everything from a Database - MySQL

I was wondering if there is a way to get everything (all records) from a database? Then the user will have the option to save that file as an excel spreadsheet.

I was looking at DTS (data transformation service) is this the same thing?

Is there a specific query that can be sent through PHP to the database, would that be too much load on it?

I did some volume analysis and figured that the largest the database will ever get w开发者_如何转开发ill be no more than 40mb.

So Ideally what I want to achieve is this.

  1. Query "get everything from database"
  2. My PHP "recieves query result"
  3. My PHP "transforms it into an excel file"
  4. Prompt user to save excel file

Is this possible?

Thanks


You can only SELECT everything from a table; iterate a list of all tables (use SHOW TABLES of information_schema.tables) and run SELECT * FROM ... for each.


Databases are not spreadsheets. You can get a CSV representation of a single table containing no binary data (which Excel will open) using a SELECT ... INTO OUTFILE query.

http://dev.mysql.com/doc/refman/5.1/en/select.html


<?php
    $output = array();
    $tables = array('table1','table2','table3');
    foreach($tables as $table) {
        $sql = "SELECT * from " . $table;
        $result = mysql_query($sql);
        array_push($output, $result);
    }
    // You now have an array of database objects for each table 
    // to do with as you will.
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜