可以连接纯PHP到SQL Server 2008 Express,但不可能与Symfony3


Possible to connect pure PHP to SQL Server 2008 Express but impossible with Symfony3

我读了很多关于这个主题的帖子,并应用了建议的解决方案,但没有成功。安装PHP驱动程序后,配置PHP .ini,…我现在可以用PHP官方网站提供的纯PHP代码连接SQL Server,如下所示:

<?php
$serverName = "AMISSAH-PC'SQLEXPRESS"; //serverName'instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"epayzone");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
 echo "Connection established.<br />";
}else{
 echo "Connection could not be established.<br />";
 die( print_r( sqlsrv_errors(), true));
}
?>

但是现在在Symfony3中,当我仍然使用相同的参数时,我不能:如下:

# This file is auto-generated during the composer install
parameters:
database_driver: pdo_sqlsrv
database_host: AMISSAH-PC'SQLEXPRESS
database_port: 1433
database_name: epayzone
database_user: null
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt

我得到以下错误:

ConnectionException in AbstractMySQLDriver.php line 103: An exception occured in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. 

我很确定您正在使用Doctrine在幕后连接到数据库,请参阅pdo_sqlsrv的驱动程序文档:

"pdo_sqlsrv:使用pdo_sqlsrv的Microsoft SQL Server驱动程序PDO注意,这个驱动程序在我们的测试中会导致问题。如果可能,建议使用sqlsrv驱动程序。"

来源:http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html司机