Ndkachare
Ndkachare

Reputation: 53

How do install pdo_sqlsrv driver in elastic beanstalk to connect SQL server db instance

I am trying to connect my SQL server db instance to my PHP application in elastic beanstalk.It is giving me an error "driver 1 not found". I am using following code to connect my db instance inside same environment.

<?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 developer guide mentions to install a driver for PDO_SQLSRV. I tried installing driver by using .ebextensions folder in my application root directory with a .config file to install the package.

packages: 
yum:
php56-mssql: [] 

but this result in degrading my environment health to server.

I used this links as my reference 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 ? 

I am new to aws .Please help me to resolve this problem it would bee appreciated.

Addition info: My platform: 64bit Amazon Linux 2016.09 v2.3.3 running PHP 7.0

Upvotes: 2

Views: 2282

Answers (1)

Ndkachare
Ndkachare

Reputation: 53

After trying multiple answers, I figured out the solution for this issue.

The problem was PHP 7.0 version, for which I had to use package

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

Adding the above code in my application root directory .ebextensions/any.config file

In my case, the amazon document did not helped me because it mentions PDO_SQLSRV driver to be install but they do not support that driver instead I had to use PDO_DBLIB driver below is an example of it.

$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

Upvotes: 1

Related Questions