Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal Reports 11.5 with PHP and MySQL

I am new to Crystal Reports, and I am using version Crystal Reports 11.5.

My requirement is as below:

  1. Programming Environment is PHP .
  2. Database is MySQL.
  3. I want to generate PDF reports using Crystal Report + PHP + MySQL.

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.

like image 681
Prathamesh mhatre Avatar asked May 10 '17 10:05

Prathamesh mhatre


People also ask

Can I use Crystal Report in PHP?

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.

Does Crystal Reports work with MySQL?

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.

Is Crystal Report still used?

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.

What database does Crystal Reports use?

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.


1 Answers

Please follow the steps:

  1. 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

  2. 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

  3. Once you have altered your CRConfig.xml, close and reopen Crystal Reports.

  4. From the menu: File -> New -> Standard Report
  5. In the “Available Data Sources” list, double-click to expand “Create New Connection”
  6. Double-click to expand “JDBC (JNDI)”
  7. Double-click “Make New Connection”
  8. Connection URL: “jdbc:mysql://db.example.com/dbname” (Use your own database host name and db name). Database Classname: “com.mysql.jdbc.Driver”
  9. Click “Next”
  10. Enter a database user/password combination when prompted.

You should now be able to inspect the tables/columns in the database to begin reporting.

See reference

like image 168
Muhammad Muazzam Avatar answered Sep 27 '22 20:09

Muhammad Muazzam