Issue
Some time you may facing the following error when trying to connect to MS SQL Server from PHP using the sqlsrv_connect() function:
Error As follows: Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] =>
This extension requires the Microsoft ODBC Driver for SQL Server.
Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 [message]
=> This extension requires the Microsoft ODBC Driver for SQL Server.
Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 ) )
Environment
- CloudLinux 6/7/8
Solution
1. To configure ODBC, please perform the following actions:
1.1 In the /etc/odbcinst.ini
, add details about FreeTDS driver:
[FreeTDS]
Description = MS SQL database access with Free TDS
Driver = /opt/alt/freetds/usr/lib64/libtdsodbc.so
Setup = /usr/lib64/libtdsS.so
UsageCount = 1
* For i386/i686 lib64 use lib in path
1.2 Add details about the MSSQL server to /etc/odbc.ini
:
[mssql_odbc]
Description = MSSQL Server
Driver = FreeTDS //should have the same name as driver in /etc/odbcinst.ini
Database = %DB_NAME%
Server = %IP%
Port = %PORT%
1.3 Update CageFS:
cagefsctl --update-etc
1.4 Enable PHP extensions:selectorctl -u %USERNAME% -v %PHP_VERSION% -e pdo_odbc,odbc
1.5 Add the following syntax in the connection script:$dbh = new PDO("odbc:mssql_odbc", "sa", "%DB_USER%", "%DB_PASS%");
1.6 Also, you need to run the following commands:
/opt/alt/alt-php-config/install_odbc
cagefsctl --force-update
cagefsctl -M
So basically, you need the following PHP extensions:
pdo_odbc,odbc
To enable them, please run the following command:
selectorctl --enable-user-extensions=pdo_dblib,odbc --version=X.X --user=UserName
where x.x depends on PHP version which you use for the website.
Comments
0 comments
Please sign in to leave a comment.