简体   繁体   中英

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

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服务已开启 !

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服务已开启

确保ODBC DSN在32位或64位方面与Crystal运行时相匹配。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM