Reputation: 1085
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.
Upvotes: 17
Views: 24396
Reputation: 2800
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
Upvotes: 4