I couldn't find an example anywhere on what I was trying to do. After taking bits from everyone I ended up with something that worked.
Im using Crystal Reports 10, MS SQL Server 2005, Apache2, and PHP5.
My report uses an SQL Store Procedure and passes some parameter to get the report data, so our PHP must set the database logon info and pass the parameters.
Below is the solution I came up with:
<?php
$my_report = "C:\\Apache2\htdocs\\test\\MyReport.rpt"; $my_pdf = "C:\\Apache2\htdocs\\test\\MyReport.pdf";
$ObjectFactory= new COM("CrystalReports10.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application.10");
$creport = $crapp->OpenReport($my_report, 1);
$creport->Database->Tables(1)->SetLogOnInfo("MYSERVER", "Database", "user", "password");
$creport->EnableParameterPrompting = 0;
$creport->DiscardSavedData;
$creport->ReadRecords();
$creport->FormulaFields->Item(1)->Text = ("'My Report Title'");
$creport->ParameterFields(1)->AddCurrentValue ("FirstParameter");
$creport->ParameterFields(2)->AddCurrentValue (2000);
$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->FormatType=31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
$creport = null;
$crapp = null;
$ObjectFactory = null;
print "<embed src=\"MyReport.pdf\" width=\"100%\" height=\"100%\">"
?>
Obviously there's plenty of room for refinement in there, but it works and should get you going on the right track. I also found that during testing, the script was hanging before supressing the parameter prompt. Once this had happened, some exports that had been working earlier stopped completely and wouldn't work again untill I restarted Apache. This might be something worth doing if you keep having issues after a script has hung.