CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
write sql results to xml file


New User

Oct 18, 2010, 3:26 PM

Post #1 of 1 (1310 views)
write sql results to xml file Can't Post

Hello everyone,

I have a small perl-script that retrieves data from a database and writes the results to a text file.

What I need to accomplish is to retrieve the data same way, but instead that saving it on a text file, save it in xml format. I would like this to be not manually formatted, but using an utility if possible and not too cumbersome.

I have no prior experience working on such task, and any help figuring out the code to accomplish this would be really great.

The script to modify:

use warnings;
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';

my $objConn = Win32::OLE->new("ADODB.Connection");
my $objCommand = Win32::OLE->new("ADODB.Command");
my $objRecordSet = Win32::OLE->new("ADODB.Recordset");
$objConn->Open("Driver={Webtrends ODBC Driver};Server=mywebtrendserver;Port=7099;Database=flrdacbkoji;Uid=*****;Pwd=******;AccountId=1;Language=english;ProfileGuid=KlDwrNbKgm6;SSL=0;");
$objCommand->{"ActiveConnection"} = $objConn;
$objCommand->{"CommandText"} = "SELECT * FROM Pages WHERE Titles <> '' AND URLs IS NOT NULL AND Titles NOT LIKE 'PowerHouse TV : 404 Error Page' AND Titles NOT LIKE '302 Found' AND URLs <> '' AND URLs <> '' AND URLs <> '' ORDER BY Visits DESC";
$objRecordSet->{"CursorLocation"} = 3; #adUseClient
$objRecordSet->{"CursorType"} = 0; #adOpenForwardOnly
$objRecordSet->{"LockType"} = 1; #adLockReadOnly;

$objRecordSet = $objCommand->Execute();

open OUT, ">output.txt";

while (!$objRecordSet->EOF)
print OUT $objRecordSet->Fields("Titles")->value, ", ";
print OUT $objRecordSet->Fields("URLs")->value, ", ";
print OUT $objRecordSet->Fields("Visits")->value, ", ";
print OUT $objRecordSet->Fields("Views")->value, "\n";


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives