我正在尝试使用php脚本生成水晶报告。该脚本似乎在ReadRecords()之后挂起;日志文件中不会生成任何错误消息。我做错了吗?
$my_report = "C:\\inetpub\\wwwroot\\mamobile\\reports\\invoice.rpt";
$my_pdf = "C:\\inetpub\\wwwroot\\mamobile\\reports\\test.pdf";
$ObjectFactory = new COM("CrystalReports115.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalDesignRuntime.Application.11");
$creport = $crapp->OpenReport($my_report, 1);
$creport->EnableParameterPrompting = 0;
$creport->DiscardSavedData;
$creport->ReadRecords();
$creport->FormulaSyntax = 0;
$creport->RecordSelectionFormula = "{invoice.invoiceid} = 20070128114815";
$creport->ExportOptions->DiskFileName = $my_pdf;
$creport->ExportOptions->FormatType = 31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
$creport = null;
$crapp = null;
$ObjectFactory = null;
此代码的类似版本适用于其他报告。
$my_report = "C:\\inetpub\\wwwroot\\mamobile\\reports\\" . $name;
$my_pdf = "C:\\inetpub\\wwwroot\\mamobile\\reports\\test.pdf";
$ObjectFactory = new COM("CrystalReports115.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalDesignRuntime.Application.11");
$creport = $crapp->OpenReport($my_report, 1);
$creport->EnableParameterPrompting = 0;
$creport->DiscardSavedData;
$creport->ReadRecords();
$creport->ExportOptions->DiskFileName = $my_pdf;
$creport->ExportOptions->FormatType = 31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
$creport = null;
$crapp = null;
$ObjectFactory = null;
答案 0 :(得分:3)
这就解决了我的问题。
$my_report = "C:\\inetpub\\wwwroot\\mamobile\\reports\\invoice.rpt";
$my_pdf = "C:\\inetpub\\wwwroot\\mamobile\\reports\\test.pdf";
$ObjectFactory = new COM("CrystalReports115.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalRuntime.Application.11");
$creport = $crapp->OpenReport($my_report, 1);
$creport->EnableParameterPrompting = 0;
$creport->FormulaSyntax = 0;
$creport->DiscardSavedData();
$creport->RecordSelectionFormula = "{invoice.invoiceid} = 20070128114815";
$creport->ReadRecords();
$creport->ExportOptions->DiskFileName = $my_pdf;
$creport->ExportOptions->FormatType = 31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
$creport = null;
$crapp = null;
$ObjectFactory = null;
答案 1 :(得分:1)
您应该使用DIRECTORY_SEPARATOR
代替\\
您正在调用$creport->DiscardSavedData
- 如果这是一个变量,它什么都不做。如果是函数调用,则应为$creport->DiscardSavedData()
。
在脚本开头尝试这些设置:
ini_set('error_reporting', -1); # displays all errors
ini_set('display_errors', 1); # reports errors to browser/console