[英]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. 实际上,我尝试使用不带Apache服务的sqlsrv_connect和DSN(数据源名称)来连接SQL Server,然后两者都可以正常工作。
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). 问题是当我打开apache服务时,php无法使用odbc DSN连接到sql服务器(使用sqlsrcv_connect)。
The condition is I need to turn on the apache with a application running using sql server which using DSN. 条件是我需要使用通过使用DSN的sql服务器运行的应用程序打开apache。 I working with crystal report thats why really need this method.
我与Crystal Report合作,这就是为什么真正需要这种方法的原因。 I have tried using system DSN instead user dsn, its also not working.
我尝试使用系统DSN代替用户dsn,它也无法正常工作。
!
!
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运行时相匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.