I am new to Crystal Reports, and I am using version Crystal Reports 11.5.
My requirement is as below:
Currently, I am using COM object to connect to Crystal Report using PHP, and I am able to generate a sample static PDF report.
My main task is to do all processing in PHP by fetching values from MySQL and pass the values to Crystal Reports and generate a PDF. I need assistance to achieve this task. If anybody can provide sample code then it will be much better.
This is what I have so far:
$my_report = "E:\\xampp\\htdocs\\crystal\\Test1.rpt";
$my_pdf = "E:\\xampp\\htdocs\\crystal\\test.pdf";
$o_CrObjectFactory = new COM('CrystalReports11.ObjectFactory.1');
// Create the Crystal Reports Runtime Application.
$o_CrApplication =$o_CrObjectFactory->CreateObject("CrystalDesignRunTime.Application");
//------ Open your rpt file ------
$creport = $o_CrApplication->OpenReport($my_report, 1);
//------ Connect to DB2 DataBase ------
**this is the hard part where I am not able to complete connection to mysql**
$o_CrApplication->LogOnServer('which library','mlims','root','');
//------ Put the values that you want --------
$creport->RecordSelectionFormula="{parameter.id}='1'";
//------ This is very important. DiscardSavedData make a
// Refresh in your data -------
$creport->DiscardSavedData;
//------ Read the records :-P -------
$creport->ReadRecords();
//------ Export to PDF -------
$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->FormatType=31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
//------ Release the variables
$creport = null;
$crapp = null;
$ObjectFactory = null;
As you see In the above code, I need to connect the Mysql server which I have been trying to do for the last few days. I have tried many examples on the net, but most of them are for SQL Server, not MySQL.
Please try this method in php, you only have connectivity issue and some configuration are required at window side for crystal reports to work it correctly.
Crystal Reports can also integrate the data from multiple databases so users are not constricted to using one data source or one database or database type (MySQL, Oracle, MS SQL Server, etc) in a report.
The Standard and Professional editions were discontinued with the release of SAP Crystal Reports 2008. SAP Crystal Reports Xi Developer edition remains available and does everything that Standard and Pro could do - and more.
As one of the most popular database servers used in all types of organizations, Microsoft SQL Server finds itself as a required data source for many types of SAP Crystal Reports projects.
Please follow the steps:
Download the MySQL Connector J jar file. That download should contain a jar file that looks something like: mysql-connector-java-3.1.14-bin.jar
Add the location of your newly downloaded jar file to the Classpath, as defined in CrystalReports CRConfig.xml file. On a Windows machine, the config file will be located somewhere like: C:\Program Files\Business Objects\Common\3.5\java\CRConfig.xml
Once you have altered your CRConfig.xml, close and reopen Crystal Reports.
You should now be able to inspect the tables/columns in the database to begin reporting.
See reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With