Crystal Reports 11.5与PHP和MySQL

Pra*_*tre 17 php mysql crystal-reports reporting-services

我是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; 
Run Code Online (Sandbox Code Playgroud)

如您所见在上面的代码中,我需要连接过去几天我一直尝试做的Mysql服务器.我在网上尝试了很多例子,但大多数都是针对SQL Server而不是MySQL.

Muh*_*zam 4

请按照以下步骤操作:

\n\n
    \n
  1. 下载 MySQL连接器 J jar 文件。该下载应包含一个类似于以下内容的 jar 文件:\nmys​​ql-connector-java-3.1.14-bin.jar

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

  4. \n
  5. 更改 CRConfig.xml 后,关闭并重新打开 Crystal Reports。

  6. \n
  7. 从菜单:文件 -> 新建 -> 标准报告
  8. \n
  9. 在\xe2\x80\x9c可用数据源\xe2\x80\x9d列表中,双击展开\xe2\x80\x9c创建新连接\xe2\x80\x9d
  10. \n
  11. 双击展开\xe2\x80\x9cJDBC (JNDI)\xe2\x80\x9d
  12. \n
  13. 双击\xe2\x80\x9c建立新连接\xe2\x80\x9d
  14. \n
  15. 连接 URL:\xe2\x80\x9cjdbc:mysql://db.example.com/dbname\xe2\x80\x9d(使用您自己的数据库主机名和数据库名称)。\n数据库类名:\xe2\x80\x9ccom。 mysql.jdbc.Driver\xe2\x80\x9d
  16. \n
  17. 单击\xe2\x80\x9c下一步\xe2\x80\x9d
  18. \n
  19. 出现提示时输入数据库用户/密码组合。
  20. \n
\n\n

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

\n\n

参见参考资料

\n