Crystal Reports 11.5,包含 PHP 和 MySQL
2022-08-30 23:46:25
我是 Crystal Reports 的新手,使用的是 Crystal Reports 11.5 版本。
我的要求如下:
- 编程环境是 PHP 。
- 数据库是MySQL。
- 我想使用 Crystal Report + PHP + MySQL 生成 PDF 报告。
目前,我正在使用COM对象通过PHP连接到Crystal Report,并且能够生成一个示例静态PDF报告。
我的主要任务是通过从MySQL获取值来执行PHP中的所有处理,并将值传递给Crystal Reports并生成PDF。我需要帮助来完成这项任务。如果有人可以提供示例代码,那么它将会好得多。
这是我到目前为止所拥有的:
$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;
正如你所看到的在上面的代码中,我需要连接Mysql服务器,这是我过去几天一直在尝试做的。我在网上尝试了很多例子,但大多数都是针对SQL Server的,而不是MySQL。