If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Exporting data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-04, 06:32
m.inckle m.inckle is offline
Registered User
 
Join Date: Feb 2004
Posts: 24
Exporting data

I dont know if this is a mysql or delphi question

How can i programmatically export a table from mysql into a csv

I'm using mysql 4.0.1 and programing in delphi 5
Reply With Quote
  #2 (permalink)  
Old 07-11-04, 22:10
yellowmarker yellowmarker is offline
Registered User
 
Join Date: Jul 2004
Location: Dundee, Scotland
Posts: 107
you might use a variation of the following approach which outputs the data from any MySQL table in csv format using PHP:

do_query("SELECT * FROM table_name; ");
if (mysql_num_rows($result) == 0) {
echo("No rows found, nothing to print");
exit;
}
$field_count = mysql_num_fields($result);
for($i = 0; $i < $field_count; $i++) {
echo mysql_field_name($result,$i);
echo(",");
}
echo("\n");
while($row = mysql_fetch_array($result)) {
for($i = 0; $i < $field_count; $i++) {
echo($row[$i].",");
}
echo("\n");
}

or, you might use the "mysqldump" command-line utility with options such as:
--fields-terminated-by=...
--fields-enclosed-by=...
--fields-optionally-enclosed-by=...
--fields-escaped-by=...
--lines-terminated-by=...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On