The code for generating the Crystal Reports report works fine in the CLI, but the "data source name was not found" when accessing the browser

I am trying to create 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 the command line, it works fine, and I exported and parsed the PDF in the console.

But from the point of view of the browser, the story is different. If you get a 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 

In the report, the database connection is done through ODBC, I could not use it, because any other driver marked with ODBC refused to work.


+6
source share
2 answers

You may need to set some environment variables. The following is what I had to install to use another ODBC driver (note: on OS X).

 <?php putenv("ODBCINSTINI=/path/to/odbcinst.ini"); putenv("ODBCINI=/path/to/odbc.ini"); ?> 
+1
source

I see you are using wamp. This behavior is very likely related to the user with whom the web server (Apache) is working.

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

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

0
source

Source: https://habr.com/ru/post/887636/


All Articles