2017-06-02 71 views
1

我想我的SQL Server数据库实例连接到弹性beanstalk.It我的PHP应用程序是给我一个错误驾驶员1没有找到 ”。我正在使用下面的代码来连接我的数据库实例在同一个环境中。如何安装驱动程序PDO_SQLSRV弹性青苗连接SQL服务器数据库实例

<?php 
$dbhost = $_SERVER; 
$dbport = $_SERVER; 
$dbname = $_SERVER; 
$charset = 'utf8' ; 
$dsn = "sqlsrvl:host={$dbhost};port={$dbport};dbname={$dbname};charset={$charset}"; 
$username = $_SERVER; 
$password = $_SERVER; 
$pdo = new PDO($dsn, $username, $password); 
?> 

AWS开发人员指南提到为PDO_SQLSRV安装驱动程序。我尝试使用.config文件在我的应用程序根目录中使用.ebextensions文件夹来安装驱动程序来安装软件包。

packages: 
yum: 
php56-mssql: [] 

但这会导致我的环境对服务器的健康状况降低。

我用这个链接是我参考 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.rds.html http://techqa.info/programming/question/35984661/how-to-connect-aws-elb-to-rds-running-ms-sql

Is there any other way to install pdo_sqlsrv driver and extension in elastic beanstalk php application ? 

我是新来的AWS。请帮我解决这个问题,将蜜蜂赞赏。

加成信息: 我的平台:64位Linux的亚马逊2016.09 v2.3.3运行PHP 7.0

+0

'$ dbhost = $ _SERVER;' - 这是您的实际代码吗?因为这不会做你认为它会做的事。 – Bytewave

+0

这是我用来连接的一段代码。在php/ext文件夹中安装** pdo_sqlsrv **驱动程序并使用扩展编辑** php.ini **文件后,它在localhost上运行良好。 '延长= php_pdo_mssql.dll'。我会重复我的问题。如何在弹性beanstalk php应用程序中安装pdo_sqlsrv驱动程序和扩展?感谢@Bytewave表示有兴趣来帮助我。 – Ndkachare

+0

我跟着这个答案,但它没有帮助。[链接](https://stackoverflow.com/questions/35984661/how-to-connect-aws-elb-to-rds-running-ms-sql/35984662) – Ndkachare

回答

1

尝试多个答案之后,我想通了,对于这个问题的解决。

问题是PHP 7.0版本,我不得不用包

commands: 
    00install_mssql: 
    command: yum install -y php70-mssql 

在我的应用程序根目录.ebextensions/any.config文件

添加上面的代码在我的情况,亚马逊文件并没有帮助我,因为它提到PDO_SQLSRV驱动程序被安装,但他们不支持该驱动程序,而不得不使用PDO_DBLIB driver下面是它的一个例子。

$dbhost = 'XXXXXXXXXXX.XXXXXXXXXXXXXXX.amazonaws.com:1433'; 
$dbname = 'dbname'; 
$charset = 'utf8' ; 
$username = 'usernam'; 
$password = 'password'; 

$pdo = new PDO("dblib:host=$dbhost;Database=$dbname", $username, $password); 

$pdo->setAttribute(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL); 

$tsql ="Select InvID, Number, ProfileNum, PName, InvDate, Des 
     FROM dbname.dbo 
     WHERE ProfileNum ='" . $client_no . "' 
     AND InvDate BETWEEN '". $inv_from_date."' AND '".$inv_to_date."' 
     ORDER BY InvID"; 

ini_set('max_execution_time', 300); 

/* Execute the query.*/ 
$stmt = $pdo->query($tsql); 

    if ($stmt->execute()) 
     { echo "Statement executed.<br>\\n"; } 
    else 
     { echo "Error in statement execution.\\n"; 
      die(print_r(DBLib_error(), true)); } 

$title = $stmt->fetchColumn(3); 
print "Client Number :" . $client_no . " <br />"; 
print" Client Name &nbsp&nbsp :" . $title. ""; // Displaying Client Information 
相关问题