On Jul 17, 1:21 pm, "Paul Lautman"
wrote:
> Bre-x wrote:
> >I would like to output a odbc query to a text file. I have the
> > following php code but it isnt working.
>
> Some advice. "isnt working" [SIC] is as useful as a chocolate teapot! Things
> can "not work" in many different ways.
>
> What do you expect to see? What do you see?
from another group.....
Ah, okay. That is because you are creating the file inside of the
while, so you make a new file every time through. Try this...
Code: $sql = "SELECT bkar_inv_sonum
FROM BKARINV
WHERE bkar_inv_orddte BETWEEN('2008-06-01' and '2008-06-30')
AND bkar_inv_loc = 'UNI'
AND bkar_inv_invdte IS NULL";
if(!$rs = odbc_exec($conn, $sql)) {exit(odbc_errormsg());}
$f = fopen("tmp_temp.csv", "w");
while (odbc_fetch_array ($rs))
{
$so = odbc_result($rs,"bkar_inv_sonum")."\n";
fwrite($f, $so);
}
fclose($f);
odbc_close($conn);
Notice that the fopen happens before the while loop. It does not write
to the file until you use fclose, so it is building $f as an array.
For someone who understands, a few words will do.
>> Stay informed about: write output query to a cvs file