Results 1 to 2 of 2

Thread: Exporting data

  1. #1
    Join Date
    Feb 2004
    Posts
    24

    Unanswered: 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

  2. #2
    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=...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •