473,783 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

write output query to a cvs file

I would like to output a odbc query to a text file. I have the
following php code but it isnt working.

<?

//conneccion

$conn=odbc_conn ect('DBA','','' );
if (!$conn)
{exit("Connecti on Failed: " . $conn);}
$sql="SELECT BKAR_INV_SONUM FROM BKARINV WHERE BKAR_INV_ORDDTE >=
'2008-6-01' and BKAR_INV_ORDDTE <= '2008-6-30' AND BKAR_INV_LOC =
'UNI' AND BKAR_INV_INVDTE IS NULL";
$rs=odbc_exec($ conn,$sql);
if (!$rs)
{exit("Error in SQL");}

while (odbc_fetch_arr ay ($rs))
{
$so=odbc_result ($rs,"BKAR_INV_ SONUM");
$f = fopen("tmp_temp .csv", "w");
fwrite($f, $so);
}
fclose($f);
odbc_close($con n);
?>

I was reading on the net that I need to send the query output to an
array, but not a clue how to do it.

Thanks,
Jul 17 '08 #1
3 2718
$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_erro rmsg());}
$f = fopen("tmp_temp .csv", "w");
while (odbc_fetch_arr ay ($rs))
{
$so = odbc_result($rs ,"bkar_inv_sonu m")."\n";
fwrite($f, $so);
}
fclose($f);
odbc_close($con n);

Works very wll

Thank you

Bre-x
Jul 17 '08 #2
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?
Jul 17 '08 #3
On Jul 17, 1:21*pm, "Paul Lautman" <paul.laut...@b tinternet.com>
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_erro rmsg());}
$f = fopen("tmp_temp .csv", "w");
while (odbc_fetch_arr ay ($rs))
{
$so = odbc_result($rs ,"bkar_inv_sonu m")."\n";
fwrite($f, $so);
}
fclose($f);
odbc_close($con n);

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.
Jul 18 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3921
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL column table names. I know that there are codes to generate tabs and carriage returns, but can't find anything about including "commas" in a string to output to the file to separate the custom field names. I'd appreciate some help with a line of...
6
4622
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to console as well as to file, my code is as below, ======================================================================= #include <iostream.h> #include<ostream> #include<sstream>
2
2088
by: jeff_zhang446 | last post by:
Hi, I try to write some data structure into a file as below and would appreciate if someone can give me some advice here. The output file looks like below: row(1) 100 1 0 0 0 0 0 0 0 1 row(2) 150 5 0 0 0 0 0 0 0 2 row(3) 160 7 0 0 0 0 0 0 0 3
1
1509
by: joy_julia446 | last post by:
Hi there, I would like to print my result as below in an output file. I would appreciate if someone can give me some advice. RESULT ClassA,96.678,88.196,8.048,-0.233,456.231,5.890, 1 11.371,-0.906,-0.025,9999.888,76.888,0.001,3456.899 2 20.422,-20.979,0.422,4567.987,987.987,0.985,0.445, 3 -0.044,0.905,1.335,890.987,34.567,32.235,76.874; 4
14
2682
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure if it is apache, or php, or just an error I am not seeing. here is the code: <?php /** * Loop through the resultset
4
2760
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last time i ask for an entire code or u can give me the outine of what to do and i ll do it by myself. the description is the following: the program will read a text file that contains historical price of a stock. The program will allow users to query...
0
1422
gauravgmbhr
by: gauravgmbhr | last post by:
Hi All, I am using a application that stores a scripts in a sql server table columns some times i require to use the scripts stored in table columns in a file. So i am lookin for a keyword like UNLOAD(DB2) which unload the table into a text file. IN short i am looking to write the output of an sql query into an text file. i can't use any utility or anr dos command to do so. can it be done on just query level? Regards,
4
5304
by: myth0s | last post by:
(After thinking about it, maybe this should have been posted in the .NET forum...) Hi, I have a stored procedure in SQL Server that sends me a 3000+ char pre-formatted XML string. I use "FOR XML EXPLICIT" and it works really well when I do the query in Management Studio. But, when it comes to output, something goes wrong. My output code is very basic, I don't know if it could be better. I use ExecuteScalar since the procedure returns...
5
3675
by: Jon Skeet [C# MVP] | last post by:
On Sep 9, 9:41 am, raylopez99 <raylope...@yahoo.comwrote: It's tricky in .NET for two reasons: 1) LINQ doesn't have any concept of "remove" 2) List<T>.RemoveAll doesn't pass in the index (which makes sense as it would then need to If List<Tsupported some sort of "view" which also exposed RemoveAll, it would be easy:
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.