2.8.21. Work with MS SQL

On the hosting, there are tools available for working with external Microsoft SQL Server (MS SQL) databases.

The Mssql extension is available by default.

Available modules:

Before using the extension on the site, it must be enabled in the list of extensions in the PHP settings. In the console and cron modules are available by default.

Using PDO:

$link = new PDO("sqlsrv:Server={$server};Database={$dbname}", $login, $passwd);
$link->query("select getdate()");

Using SQLSRV:

$link = sqlsrv_connect($server, ["Database"=>$dbname, "UID"=>$login, "PWD"=>$passwd]);
sqlsrv_query($link, "select getdate()");

The variables $server, $dbname, $login and $passwd should contain the MS SQL server host, database name, username, and password, respectively.

Content