You are here: Re: How to convert MYSQL data result to csv file format. « All PHP « IT news, forums, messages
Re: How to convert MYSQL data result to csv file format.

Posted by NN on 12/29/07 15:22

On Fri, 28 Dec 2007 09:41:11 -0800 (PST), NC <nc@iname.com> wrote:

i tried the script and it works great!
i have a question. i added a link to download the file created with
the url of the file. when i run it on my wamp server i click on the
link and it prompts me to save the file, when i run it on my web
server the csv opens in the browser instead of prompting to save the
file.
any idea of how to solve this?
does it have to do with the php.ini settings?

thank you,
NN


>On Dec 28, 2:15 am, anu <anunanni2...@gmail.com> wrote:
>>
>> How to convert MYSQL data result to csv file format.
>
>The high-performance solution is to run a SELECT INTO OUTFILE query:
>
>http://dev.mysql.com/doc/refman/4.1/en/select.html
>
>The drawback of this approach is that the CSV file can only be created
>on the machine where MySQL server is running, which may or may not be
>feasible in your particular case.
>
>The alternative is to simply dump the data into a file:
>
>// Assume that the DB connection has already been established...
>$result = mysql_query('SELECT * FROM myTable');
>$fp = fopen('data.csv', 'w');
>if ($fp == false) {
> die("Could not open data.csv for writing");
>}
>while ($record = mysql_fetch_row($result)) {
> fputcsv($fp, $record);
>}
>fclose($fp);
>
>Note that fputcsv() is available only since PHP 5.1, so you may have
>to write your own CSV formatter if you have an earlier version of
>PHP...
>
>Cheers,
>NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация