fwrite() question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Collins

    fwrite() question

    Hello,

    I would like to take the data from a mysql result set, and write the
    results to a file using fwrite(). The problem I'm having now is the
    file I'm writing to only shows the php code, instead of the actual
    interpreted mysql data. My goal is to create a txt file containing
    data from my web orders, so I can import that data into my accounting
    software. Does anyone have any suggestions for me?

    I really appreciate any help with this matter.

    Aaron;
  • Paul Wellner Bou

    #2
    Re: fwrite() question

    Aaron Collins wrote:[color=blue]
    > I would like to take the data from a mysql result set, and write the
    > results to a file using fwrite(). The problem I'm having now is the
    > file I'm writing to only shows the php code, instead of the actual
    > interpreted mysql data.[/color]

    ....I _really_ would like to know what you have done there...
    [color=blue]
    > My goal is to create a txt file containing
    > data from my web orders, so I can import that data into my accounting
    > software. Does anyone have any suggestions for me?[/color]

    Something like this?

    $res = mysql_query("SE LECT * FROM yourTable");
    $textToWrite = "";

    while($row = mysql_fetch_ass oc($res))
    {
    foreach($row as $columnContent)
    {
    $textToWrite .= "\".addslashes( $columnContent) ."\",";
    }
    $textToWrite .= preg_replace("/,$/","\n",$textToW rite);
    }

    $textFile = "/path/to/file.csv";
    $fp = fopen($textfile , "r+");
    fwrite($fp, $textToWrite);
    @fclose($fp);

    [not tested]

    hth
    Paul.

    p.d.: I'm sure there are millions of scripts like this to export mysql
    databases into a (like i did here) csv (comma separated values) file
    or similar. The MySQLcc does have this feature, too.

    Comment

    Working...