Jump to content

How to create a file using PHP ?


jd2007

Recommended Posts

This is quite easy, even if your question is quite vague...

This one reads data from an odbc source, and writes a csv file to the local drive... I just happen to be working on it so I just posted it as is...

<?php
$Sunday=date('Y-m-d', strtotime("last Sunday"));
$OUTPUT='';
//$i=44296;
$i=0;
$tab='\t';
$file = "./VQTestHistorySS3.TXT";

$fp = fopen($file,"a");

$connect = odbc_connect("QES9000", "", "");

$query = "SELECT
    itdatshta.`it_date`, itdatshta.`insptype`, itdatshta.`process`, itdatshta.`product`, itdatshta.`serialno`, itdatshta.`failed`,
    itdatshtda.`descr`, itdatshtda.`hi`, itdatshtda.`lo`, itdatshtda.`units`, itdatshtda.`actual`, itdatshtda.`gonogo`, itdatshtda.`step`
FROM
    `itdatshta` itdatshta INNER JOIN `itdatshtda` itdatshtda ON
        itdatshta.`datshtid` = itdatshtda.`datshtid` AND
    itdatshta.`sample` = itdatshtda.`sample`
WHERE
    itdatshta.`product` like 'T%SS3%' AND
    (itdatshta.`process` = 'VQ Functional Outputs' OR
    itdatshta.`process` = 'VQ Functional Inputs' OR
    itdatshta.`process` = 'QA Evaluation' OR
    itdatshta.`process` = 'Functional Test') AND
    itdatshta.`failed` = 0 AND itdatshta.`it_date` < {d '$Sunday'}
ORDER BY
    itdatshta.`it_date` ASC,
    itdatshta.`serialno` ASC,
    itdatshta.`process` ASC";

$result = odbc_do($connect, $query);
WHILE($row=odbc_fetch_array($result))
{
$i++;
$OUTPUT = $i."\t".rtrim($row['it_date'])."\t".rtrim($row['insptype'])."\t".rtrim($row['process'])."\t".rtrim($row['product'])."\t".rtrim($row['serialno'])."\t".rtrim($row['step'])."\t".rtrim($row['descr'])."\t".rtrim($row['hi'])."\t".rtrim($row['lo'])."\t".rtrim($row['units'])."\t".rtrim($row['actual'])."\t".rtrim($row['gonogo'])."\t YES";
fwrite($fp, $OUTPUT."\n");

}
fclose($fp);
odbc_close($connect);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.