How to connect AWS ELB to RDS running MS SQL?

本小妞迷上赌 提交于 2019-12-04 19:35:17

The solution is to choose Amazon Linux version 5.3 when creating your beanstalk application.

After choosing PHP on the Environment Type screen, the next line says:

AWS Elastic Beanstalk will create an environment running PHP 5.6 on 64bit Amazon Linux 2015.09 v2.0.8. Change platform version.

Click the link Change platform version and you will be given a drop-down of possible versions.

The only version that seems to work is the last one on the list: 5.3 on 64bit Amazon Linux (I did not try 32bit, bit it probably also works.)

Then create a 01.config file that resides in the .ebextensions folder and make sure it includes:

packages: 
  yum:
    php-mssql: []

Beware: Indentation counts in this file.

You can now use code like this to connect:

<?php
// connect to database server
$db_conn = mssql_connect("your.rds.amazonaws.com","user","passw0rd")
   or die( "<strong>ERROR: Connection to MYSERVER failed</strong>" );

// select database - only if we want to query another database than the default one
mssql_select_db( "database1", $db_conn )
   or die( "<strong>ERROR: Selecting database failed</strong>" );

// query the database
$query_result = mssql_query( "SELECT * FROM table1", $db_conn )
   or die( "<strong>ERROR: Query failed</strong>" );
$row = mssql_fetch_array($query_result);
echo $row[0];
?>

Now it works as expected.

This is the result of 2 days work, shared here as this info does not seem to exist anywhere.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!