php - 带有 PHP 和 MySQL 的 Crystal Reports 11.5

标签 php mysql reporting-services crystal-reports

我是 Crystal Reports 的新手,我使用的是 Crystal Reports 11.5 版本。

我的要求如下:

  1. 编程环境是PHP。
  2. 数据库是MySQL。
  3. 我想使用 Crystal Report + PHP + MySQL 生成 PDF 报告。

目前,我使用 COM 对象通过 PHP 连接到 Crystal Report,并且能够生成示例静态 PDF 报告。

我的主要任务是通过从 MySQL 获取值并将值传递给 Crystal Reports 并生成 PDF 来使用 PHP 进行所有处理。我需要帮助才能完成这项任务。如果有人能提供示例代码,那就更好了。

这是我目前所拥有的:

$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。

最佳答案

请按照以下步骤操作:

  1. 下载 MySQL Connector J jar 文件。该下载应包含一个类似于以下内容的 jar 文件: mysql-connector-java-3.1.14-bin.jar

  2. 将新下载的 jar 文件的位置添加到类路径,如 CrystalReports CRConfig.xml 文件中所定义。在 Windows 机器上,配置文件将位于如下位置: C:\Program Files\Business Objects\Common\3.5\java\CRConfig.xml

  3. 更改 CRConfig.xml 后,关闭并重新打开 Crystal Reports。

  4. 从菜单:文件 -> 新建 -> 标准报告
  5. 在“可用数据源”列表中,双击以展开“创建新连接”
  6. 双击展开“JDBC (JNDI)”
  7. 双击“建立新连接”
  8. 连接 URL:“jdbc:mysql://db.example.com/dbname”(使用您自己的数据库主机名和数据库名称)。 数据库类名:“com.mysql.jdbc.Driver”
  9. 点击“下一步”
  10. 出现提示时输入数据库用户/密码组合。

您现在应该能够检查数据库中的表/列以开始报告。

reference

关于php - 带有 PHP 和 MySQL 的 Crystal Reports 11.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43889488/

相关文章:

php - Laravel blade : if. .else 语句行为异常

php - Laravel 5 InvalidArgumentException 在 FileViewFinder.php 第 137 行 : View [. admin] 未找到

php - 数据未插入但没有错误 PHP 使用 bind_param

mysql - 对于 mysql,索引对非唯一列有帮助吗?

sql-server - SSRS 可以支持 Multi-Tenancy 使用吗?

sql-server - SSRS 2005 缺少 Microsoft.ReportingServices.Interfaces.dll

php - 通过php将图像上传到mysql数据库

mysql - 返回序号

mysql - 我需要从 mysql 表中获取所有唯一数据并将其放入新表中

asp.net - 可调整大小的 html 报告