开发者

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

开发者 https://www.devze.com 2023-03-03 19:20 出处:网络
I\'m trying to generate a report from PHP, using Crystal Reports, The code seems to be correct: <?php

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= $开发者_如何学JAVApath."\\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.



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");
?>


I see you are using Wamp. This behaviour is very probably related to the user that the web server (Apache) runs under.

When you run PHP from CLI, PHP.exe inherits your user profile (in terms of database/network/filesystem access rights); on the other hand, usually Apache (and IIS,too) runs under different, unprivileged credentials, to prevent hackers from damaging and exploiting the server.

In Apache, you can change this behaviour modifying the httpd.conf Apache config file (in your case it could be located under C:\wamp\apache\conf), changing the User and/or Group config directives.

0

精彩评论

暂无评论...
验证码 换一张
取 消