There are two ways to establish a connection with MSSQL:
DBLIB
Configure alt-freeTDS:
Add to /opt/alt/freetds/etc/freetds.conf the following details about MSSQL:
[my_mssql]
host = %IP%
port = %PORT%
Then enable module for user pdo_dblib:
selectorctl -u %USERNAME% -v %PHP_VERSION% -e pdo_dblib
Use the following code to establish connection with MSSQL:
$dbh = new PDO("dblib:host=my_mssql;dbname=%DB_NAME%", "%DB_USER%", P.S: "%DB_PASS%");
Alternative way (without updating /opt/alt/freetds/etc/freetds.conf)
Use full connection string
$dbh = new PDO("dblib:host=%IP%;port=%PORT%;dbname=%DB_NAME%", "%DB_USER%", "%DB_PASS%");
Configure ODBC
In /etc/odbcinst.ini add FreeTDS driver details:
[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 use lib instead of lib64 in paths
To /etc/odbc.ini add details about MSSQL server:
[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%
Update CageFS:
cagefsctl --update-etc
Enable PHP extensions:
selectorctl -u %USERNAME% -v %PHP_VERSION% -e pdo_odbc,odbc
Add the following to the connection script:
$dbh = new PDO("odbc:mssql_odbc", "sa", "%DB_USER%", "%DB_PASS%");
Also, you need to perform the following:
/opt/alt/alt-php-config/install_odbc
cagefsctl --force-update
cagefsctl -M
Comments
0 comments
Please sign in to leave a comment.