Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code to generate Crystal Reports report works fine in CLI, but "Data source name not found" when accessed from browser

I'm trying to generate a report from PHP, using Crystal Reports, The code seems to be correct:

<?php
set_time_limit(0);
if(isset($_GET['id']))
{
$id = $_GET['id'];
} else {
die('Please specify an ID');
}

$path = "c:\\wamp\\www\\billing\\reports";
$file = $chemin."\\bill_".$id.".pdf";
$app_obj = new COM("CrystalRuntime.Application") or Die ("Did not open");
$report= $path."\\bill.rpt";

$rpt_obj= $app_obj->OpenReport($report,1);
$app_obj->LogOnServer("p2ssql.dll","host","bdd","userbd","passwordbd");
$rpt_obj->EnableParameterPrompting = FALSE;
$rpt_obj->RecordSelectionFormula = "{F_DOCLIGNE.DO_Piece}='$id'";

$rpt_obj->ExportOptions->DiskFileName =  $file;
$rpt_obj->ExportOptions->PDFExportAllPages = true;
$rpt_obj->ExportOptions->DestinationType = 1;
$rpt_obj->ExportOptions->FormatType = 31; 
$rpt_obj->Export(false);

header("Content-Type: application/pdf");
readfile($file);
?>

If I run the script from command line, it works just fine, and I have the PDF exported and parsed in the console.

But from a browser's point of view, the story is different, If you get the request through Apache, I get this exception :

com_exception: Source: Crystal Reports ActiveX Designer
Details : IM002:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified in C:\wamp\www\facture\report.php on line 25

On the report, the database connection is made through ODBC, I couldn't use that, as any other driver, marked with ODBC refused to work.


like image 605
logicbloke Avatar asked May 09 '11 15:05

logicbloke


1 Answers

You may have to set some environmental variables. Below is what I had to set to use a different ODBC driver (note: on OS X).

<?php
    putenv("ODBCINSTINI=/path/to/odbcinst.ini");
    putenv("ODBCINI=/path/to/odbc.ini");
?>
like image 134
Tim Dearborn Avatar answered Nov 03 '22 10:11

Tim Dearborn