cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report with PHP

Former Member
0 Kudos

Hi, I am new to crystal report. I want to use CR 11 integrated with my web based application. Now as entire application is designed in PHP, I need to use PHP, use COM, to pass parameters and generate PDF report.

I have following question.

Will I need CR server ?

How do i actually invoke CR from PHP ?

Right now I am doing following

$my_report = "C:
Inetpub
wwwroot
test
test.rpt";

$my_pdf = "C:\Inetpub\wwwroot\test
MyReport.pdf";

try

{

$ObjectFactory = new COM ( 'CrystalRuntime.Application' );

}

catch ( exception $e )

{

echo 'caught exception: ' . $e->getMessage () . ', error trace: ' . $e->getTraceAsString ();

}

$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application");

$creport = $crapp->OpenReport($my_report, 1);

$creport->Database->Tables(1)->SetLogOnInfo("server IP address", "db_name", "username", "password");

$creport->EnableParameterPrompting = 0;

$creport->DiscardSavedData;

$creport->ReadRecords();

$creport->FormulaFields->Item(1)->Text = ("'My Report Title'");

$creport->ParameterFields(1)->AddCurrentValue ("FirstParameter");

$creport->ParameterFields(2)->AddCurrentValue (2000);

$creport->ExportOptions->DiskFileName=$my_pdf;

$creport->ExportOptions->PDFExportAllPages=true;

$creport->ExportOptions->DestinationType=1;

$creport->ExportOptions->FormatType=31;

$creport->Export(false);

$creport = null;

$crapp = null;

$ObjectFactory = null;

but i am getting following error

caught exception: Failed to create COM object `CrystalRuntime.Application': Invalid syntax , error trace: #0 C:\Inetpub\wwwroot\cr_test.php(69): com->com('CrystalRuntime....') #1 Notice: Undefined variable: ObjectFactory in C:\Inetpub\wwwroot\cr_test.php on line 78 Fatal error: Call to a member function CreateObject() on a non-object in C:\Inetpub\wwwroot\cr_test.php on line 78

I will appreciate any help provided in this matter

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank you.

I have gone through the document.

Looks like classic ASP is not one of the supported languages, am I correct on this one ?

former_member183750
Active Contributor
0 Kudos

Classic ASP is supported - with the RDC SDK. Lots of info on ASP - type ASP Crystal in the search box at the top right corner of this web page.

- Ludek

Answers (7)

Answers (7)

Former Member
0 Kudos

Did anyone ever get PHP-Crystal combination to work using "CrystalReports14.ObjectFactory.1"?  I have reached as far as Chaitan Sukhadia on 11 June 2011, and I'm also running into the problem with the OpenReport() method.  I am constrained to using PHP per business policy, so going to classic ASP isn't a possibility (yet).  Thanks!

My code so far:

$ObjectFactory = new COM("CrystalReports14.ObjectFactory.1") or die("CR loading failed");

$crapp = $ObjectFactory-> CreateObject("CrystalReports14.ObjectFactory.1");

$creport = $crapp->OpenReport("filename.rpt", 1);

I'm not sure whether I'm using the wrong app ID when doing CreateObject(), or something else...

Thanks.

Former Member
0 Kudos

Thank you Ludek Uher for your help and quick reply.

I will use classic ASP.

Thank you for all the help you have provided.

former_member184995
Active Contributor
0 Kudos

Just for reference, no, ASP is not supported with any currently supported version of Crystal except for XI R2 and that is only for 2 more weeks (as of June 30th XI R2 is out of support and it is the last version that supports COM/ASP ).

Jason

Former Member
0 Kudos

Hi,

I have just downloaded Free 30 day Trial version from SAP Crystal Reports Download website, as at my company is planning to purchase and implement it, and made me responsible for this. And this is the version that has been downloaded.

I just gone to Help -> About Crystal Report, and this is the version number shown there.

I dont know any further detail about why I have this version.

Can you please give me list of all fully supported languages ?

I want to switch from PHP to one of the fully supported language.

Thanks and Regards

former_member183750
Active Contributor
0 Kudos

With CR 2011, there is not SDK support of any kind.

With CR XIR2A, see:

http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7081b21c-911e-2b10-678e-fe062159b...

- Ludek

Former Member
0 Kudos

Hi,

Can you please let me know list of supported languages ?

Thanks and Regards

former_member183750
Active Contributor
0 Kudos

Version 14?!

Where did this come from? Are you using the Beta of CRVS2010?

Note that CR XI R2 (11.5) was the last version of CR to ship the rdc (craxdrt.dll.). Using the craxdrt.dll from any other version is not within your license agreement...

Also, even if you go with the RDC, breaking your license agreement, you will never be able to deploy the CR runtime successfully as there are no MSM or MSI files...

- Ludek

Edited by: Ludek Uher on Jun 13, 2011 6:37 AM

Former Member
0 Kudos

Thank you. Ludek Uher

Just after I posted my update, I realized that there was an error in version I am passing, i actually have version 14.0.0.760 RTM

Now my code is like this


$my_report = "C:\\MyReport.rpt";
$my_pdf = "C:\\MyReport.pdf";

try  
{  
    $ObjectFactory = new COM ( 'CrystalReports14.ObjectFactory.1' );  
}  
catch ( exception $e )  
{  
    echo 'caught exception: ' . $e->getMessage () . ', error trace: ' . $e->getTraceAsString ();  
} 
$crapp = $ObjectFactory->CreateObject("CrystalReports14.ObjectFactory.1");

$creport = $crapp->OpenReport($my_report, 1);

and it creating creating Crystal Reports object. Now the problem I am facing is that the method OpenReport() is not working.

Does the RPT file mentioned in $my_report variable should exists when I run this code?

The same question also goes for the PDF file I am mentioning in $my_pdf variable.

former_member183750
Active Contributor
0 Kudos

Will I need CR server ?

- No you will not

How do i actually invoke CR from PHP ?

- I have no idea. PHP is not a supported language, thus I have never even seen PHP. However, as you will be using COM, you will have to use the Report Designer Component (RDC) - more bellow.

The error:

Failed to create COM object `CrystalRuntime.Application'

and the code indicates that you are not instantiating the Application runtime object correctly.

E.g.; instead of:




$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application");

try:

$crapp = $ObjectFactory->CreateObject("CrystalRuntime.Application.11");


Now, the above assumes you are using CR XI R1 (11.0). It's usually a good idea to be exact in the version of CR used (See Help | About Crystal... in the CR designer).

Other RDC resources (all will be for VB6).

Sample apps

http://www.sdn.sap.com/irj/boc/businessobjects-samples

http://wiki.sdn.sap.com/wiki/display/BOBJ/ReportDesignerComponentSDKCOM+Samples

http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/00635998-751e-2b10-9cba-f50ee1e4ef81

Also, please note

1) CR XI R1 (11.0) is out of support, CR XI R2 (11.5) will be out of support end of this month.

2) CR XI R2 is the last version of CR to ship the RDC

3) I would highly recommend updating your install to CR XI R2A. See the blog [Where did all the Crystal Reports XI R1 and R2 fixes go?|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/24977] [original link is broken];

Ludek

Follow us on Twitter http://twitter.com/SAPCRNetSup

Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Former Member
0 Kudos

Just a quick update, I am using CR Developer Version 14.0.0.760 RTM