Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Crystal Report via PHP Hangs

I'm trying to generate a crystal report using a php script. The script seems to hang just after ReadRecords(); No error message is generated in the log file. Am I doing somethign wrong?

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

A similar version of this code works for a different report.

$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;
like image 854
Hackmodford Avatar asked Feb 01 '16 22:02

Hackmodford


2 Answers

This is what fixed my problem.

$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;
like image 150
Hackmodford Avatar answered Nov 15 '22 05:11

Hackmodford


  1. You should use DIRECTORY_SEPARATOR instead of \\

  2. You are calling $creport->DiscardSavedData - if this is a variable, it does nothing. If it is a function-call, it should be $creport->DiscardSavedData().

  3. try these settings at the beginning of your script:

    ini_set('error_reporting', -1); # displays all errors
    ini_set('display_errors', 1);   # reports errors to browser/console
    
like image 23
Roman Avatar answered Nov 15 '22 03:11

Roman