Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Want to export and import data...

This is a discussion on Want to export and import data... within the PHP forums, part of the Programming Talk category; In a fixed length format I would like to import and export data from Mysql using phpscript ....Please if anyone ...

  1. #1
    rachelle is offline Member Array
    Join Date
    Apr 2006
    Answers
    97

    Want to export and import data...

    In a fixed length format I would like to import and export data from Mysql using phpscript ....Please if anyone knows let me know

    Thanks in advance


  2. #2
    techguru is offline Senior Member Array
    Join Date
    Mar 2005
    Answers
    112
    it will be some thing like this...

    Code:
     
    $select = “SELECT * FROM MYNAME";
    $export = mysql_query($select);
    $count = mysql_num_fields($export);
    Extract field names and write them to the $header variable
    for ($i = 0; $i < $count; $i++) {
    $header .= mysql_field_name($export, $i)."t";
    }
    Extract all data, format it, and assign to the $data variable
    /**********/
    while($row = mysql_fetch_row($export)) {
    $line = ‘’;
    foreach($row as $value) {
    if ((!isset($value)) OR ($value == “")) {
    $value = “t";
    } else {
    $value = str_replace(’"‘, ‘""‘, $value);
    $value = ‘"‘ . $value . ‘"‘ . “t";
    }
    $line .= $value;
    }
    $data .= trim($line)."n";
    }
    $data = str_replace("r", “", $data);
    /************
     
    /************/
    if ($data == “") {
    $data = “n(0) Records Found!n";
    }
    print “$headern$data";
    You need to create a file then write the record to it ... if you need fixed lenght, you may need to pad each field with specific legnth you need.



    Last edited by techguru; 10-11-2006 at 06:42 AM.

Latest Article

Network Security Risk Assessment and Measurement

Read More...