Re: PHP and Crystal Reports

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/4/30 John Messam <johnmess@xxxxxxxxxxx>:
> Thank you for responding.  I get the following
> <
> Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b>
> Unknown<br/><b>Description:</b> Unknown' in C:\wamp\www\ledermode\cr4.php:15
> Stack trace: #0 C:\wamp\www\ledermode\cr4.php(15):
> com->CreateObject('CrystalRunTime....') #1 {main} thrown in
> C:\wamp\www\ledermode\cr4.php on line 15
>
> Your comments please.
>
>> From: rquadling@xxxxxxxxxxxxxx
>> Date: Thu, 30 Apr 2009 09:03:16 +0100
>> To: johnmess@xxxxxxxxxxx
>> CC: php-windows@xxxxxxxxxxxxx
>> Subject: Re:  PHP and Crystal Reports
>>
>> 2009/4/30 John Messam <johnmess@xxxxxxxxxxx>:
>> >
>> > I am trying to write a php program that opens a number of reports
>> > written in Crystal 11. From research on the internet, I found that CR would
>> > have to be called using COM.  So I did that. From the command line it
>> > triggers a dialog box saying that the version of Crystal the reports was
>> > written in was later than the one that is being used to open it via the php
>> > program.   The other problem is that when it is run from the browser the
>> > program hangs on the openReport command
>> >
>> >
>> >
>> > Can anyone assist me on resolving the hanging issue or the entire thing
>> > for that matter.
>> >
>> >
>> >
>> > Thanks!
>> >
>> >
>> >
>> > John
>> >
>> > _________________________________________________________________
>> > Show them the way! Add maps and directions to your party invites.
>> > http://www.microsoft.com/windows/windowslive/products/events.aspx
>>
>> I use Crystal all day and via PHP also.
>>
>> Here is the code I use (edited). It might not be perfect, but it works
>> perfectly.
>>
>> <?php
>> // Create an Crystal Object Factory.
>> $o_CrObjectFactory = new COM('CrystalReports11.ObjectFactory.1');
>>
>> // Create the Crystal Reports Runtime Application.
>> $o_CrApplication =
>> $o_CrObjectFactory->CreateObject("CrystalRunTime.Application.11");
>>
>> // Register the typelibrary.
>> com_load_typelib('CrystalDesignRunTime.Application');
>>
>> // Load the report.
>> $o_CrReport = $o_CrApplication->OpenReport('C:\Report.rpt', 1); // 1
>> == crOpenReportByTempCopy.
>>
>> // Logon to the database.
>> $o_CrReport->Database->LogOnServer
>> (
>> 'odbc',
>> 'Accounts',
>> registryDatabaseLocations::Database('Accounts'),
>> registryDatabaseLocations::Username('Accounts'),
>> registryDatabaseLocations::Password('Accounts')
>> );
>>
>> // Don't tell anyone what is going on when running live.
>> $o_CrReport->DisplayProgressDialog = False;
>>
>> $s_ExportedReport = 'C:\Report.pdf';
>>
>> // Run the report and save the PDF to disk.
>> $o_CrReport->ExportOptions->DiskFileName = $s_ExportedReport;
>> $o_CrReport->ExportOptions->PDFExportAllPages = True;
>> $o_CrReport->ExportOptions->DestinationType = 1; // Export to File
>> $o_CrReport->ExportOptions->FormatType = 31; // 31 = PDF, 36 = XLS, 14 =
>> DOC
>>
>> // Assign the parameters to the report.
>> $m_Stuff = new Variant();
>>
>> $o_CrPeriodsParam =
>> $o_CrReport->ParameterFields->GetItemByName('PeriodIDs', $m_Stuff);
>> $o_CrPeriodsParam->ClearCurrentValueAndRange();
>>
>> foreach($_SESSION['tabRG_PeriodIDs'] as $i_Period)
>> {
>> $o_CrPeriodsParam->AddCurrentValue(intval($i_Period));
>> }
>>
>> $o_CrReport->ReadRecords();
>> $o_CrReport->Export(False);
>> ?>
>>
>>
>>
>> --
>> -----
>> Richard Quadling
>> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
>> "Standing on the shoulders of some very clever giants!"
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> ________________________________
> Invite your mail contacts to join your friends list with Windows Live
> Spaces. It's easy! Try it!

Did you edit the code to fit your requirements? I don't know what your
report uses for a database, so you will need to amend the login
details.

Judging by the fact that it was line 15 that went wrong, it looks like
the Crystal Runtime is installed correctly.

Essentially when you run Crystal you need to logon to the data source.
My code uses a registry class to extract the credentials (and I use
ODBC for all of the reports, though to different types of data -
MSSQL, Excel, Sage Retrieve 4GL, etc.)

-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux