Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
How to convert MYSQL data result to csv file format.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
anu  
View profile  
 More options Dec 28 2007, 5:15 am
Newsgroups: alt.php
From: anu <anunanni2...@gmail.com>
Date: Fri, 28 Dec 2007 02:15:07 -0800 (PST)
Local: Fri, Dec 28 2007 5:15 am
Subject: How to convert MYSQL data result to csv file format.

hi all,

  How to convert MYSQL data result to csv file format.

Thanks,
Anu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jerry Stuckle  
View profile  
 More options Dec 28 2007, 8:59 am
Newsgroups: alt.php
From: Jerry Stuckle <jstuck...@attglobal.net>
Date: Fri, 28 Dec 2007 08:59:00 -0500
Subject: Re: How to convert MYSQL data result to csv file format.

anu wrote:

> hi all,

>   How to convert MYSQL data result to csv file format.

> Thanks,
> Anu

If you're looking for a way to do it in SQL, try comp.databases.mysql.

If you're looking for a way to do it in PHP, what have you tried?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NC  
View profile  
 More options Dec 28 2007, 12:41 pm
Newsgroups: alt.php
From: NC <n...@iname.com>
Date: Fri, 28 Dec 2007 09:41:11 -0800 (PST)
Local: Fri, Dec 28 2007 12:41 pm
Subject: Re: How to convert MYSQL data result to csv file format.
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NN  
View profile  
 More options Dec 29 2007, 10:22 am
Newsgroups: alt.php
From: NN <NoN...@home.com>
Date: Sat, 29 Dec 2007 09:22:18 -0600
Local: Sat, Dec 29 2007 10:22 am
Subject: Re: How to convert MYSQL data result to csv file format.

On Fri, 28 Dec 2007 09:41:11 -0800 (PST), NC <n...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pacal  
View profile  
 More options Dec 29 2007, 2:10 pm
Newsgroups: alt.php
From: pacal <pa...@pacal.invalid>
Date: Sat, 29 Dec 2007 20:10:20 +0100
Local: Sat, Dec 29 2007 2:10 pm
Subject: Re: How to convert MYSQL data result to csv file format.
NN schreef:
> On Fri, 28 Dec 2007 09:41:11 -0800 (PST), NC <n...@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

create a new php witch includes the csv
and start the headers of the file with

<?php
header("Content-type: application/vnd.ms-excel");
header("Content-disposition:  attachment; filename="filename.csv");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
include("filename.csv");
?>

and run that file instead of the csv

you could also remove the include and build the csv from scratch there

header("bla bla")
echo
"\"fieldname1\";\"fieldname2\";\"fieldname3\";\"fieldname4\";\"etc\"\n";

database extraction
select * from etc
while($row = mysql_fetch_object($resultaat))
{
some if then filtering;
echo
"\"$row->content1\";\"$row->content2\";\"$row->content3\";\"$row->content4\ ";\"etc\"\n";

}

  and if the file gets big dont forget to set
set_time_limit(0);
at the top of the file to reset the standard php ini settings

works great for me and i am able to create filters to give the csv i
want with the values i want

greets
pacal


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NN  
View profile  
 More options Dec 30 2007, 10:49 am
Newsgroups: alt.php
From: NN <NoN...@home.com>
Date: Sun, 30 Dec 2007 09:49:28 -0600
Local: Sun, Dec 30 2007 10:49 am
Subject: Re: How to convert MYSQL data result to csv file format.
thank you very much!
i'll try that.

NN


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NC  
View profile  
 More options Dec 30 2007, 7:22 pm
Newsgroups: alt.php
From: NC <n...@iname.com>
Date: Sun, 30 Dec 2007 16:22:38 -0800 (PST)
Local: Sun, Dec 30 2007 7:22 pm
Subject: Re: How to convert MYSQL data result to csv file format.
On Dec 29, 7:22 am, NN <NoN...@home.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?

No, it has to do with HTTP headers Web servers send out before serving
actual data.

How do you solve this?  By writing a script that would send the
appropriate headers and then dump the data.  Let's assume that, in
line with the previous example, you have created a file called
data.csv.  Now you can write a script that will serve this data and
suggest to the browser that the data is to be saved as data.csv rather
than viewed in the browser:

header('Content-type: application/vnd.ms-excel');
header('Content-disposition: attachment; filename=data.csv');
readfile('data.csv');

Note, however, the word "suggest" above; the browser may choose to
ignore the "Content-disposition:" header and still display data in
browser of save it under the script's name rather than as data.csv...

Cheers,
NC


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NN  
View profile  
 More options Dec 31 2007, 10:56 am
Newsgroups: alt.php
From: NN <NoN...@home.com>
Date: Mon, 31 Dec 2007 09:56:25 -0600
Local: Mon, Dec 31 2007 10:56 am
Subject: Re: How to convert MYSQL data result to csv file format.
thank you!. i'll try it and see if it works on my server.

thanks,
NN


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »