Categories: php, sql-server, apache, odbc, dsn

How to connect SQL Server through DSN in PHP Apache ? (It's not working when Apache Service is On)

1 answer

Actually I have try to connect SQL server by using sqlsrv_connect and using the DSN (Data Source Name) without Apache service then the both are perfectly working.

The problem is when I turn on the apache service then php cannot connect to the sql server using odbc DSN (Working with sqlsrcv_connect).

The condition is I need to turn on the apache with a application running using sql server which using DSN. I working with crystal report thats why really need this method. I have tried using system DSN instead user dsn, its also not working.

Apache Service is on !

I wrote code below to test my scenario

 // Connect to the data source  $conn=odbc_connect('DSNNAME','DBUSER','DBPASS'); if ($conn){      echo "Connection established DSN"; } else {       echo "Connection using DSN Failed:" . odbc_errormsg(); }  // Connect through server name   $serverName = "WEBSERVER\SQLEXPRESS"; //serverName\instanceName, portNumber (default is 1433) $connectionInfo = array( "Database"=>"DBNAME", "UID"=>"DBUSER", "PWD"=>"DBPASS"); $conn2 = sqlsrv_connect( $serverName, $connectionInfo);  if( $conn2 ) {      echo "Connection established using server name"; }else{      echo "Connection could not be established by using server name";      die( print_r( sqlsrv_errors(), true)); } 

The Result when Apache service is on.

Apache Service is on

All answers to this question, which has the identifier 57786604

The best answer:

Make sure the ODBC DSN matches the Crystal runtime in terms of 32-bit or 64-bit.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data