---
title: "Connecting to MSSQL"
canonical_url: "https://www.zone.lv/help/kb/connecting-to-mssql/"
post_type: "ht_kb"
published: "2024-04-17T08:22:47+00:00"
modified: "2024-04-19T07:42:08+00:00"
language: "en"
author: "Hasso"
taxonomies:
  ht_kb_category:
    - name: "PHP"
      url: "https://www.zone.lv/help/kb-categories/php-en/"
  ht_kb_tag:
    - name: "connection"
      url: "https://www.zone.lv/help/kb-tags/connection/"
    - name: "database"
      url: "https://www.zone.lv/help/kb-tags/database/"
    - name: "db"
      url: "https://www.zone.lv/help/kb-tags/db/"
    - name: "ms"
      url: "https://www.zone.lv/help/kb-tags/ms/"
    - name: "ms sql"
      url: "https://www.zone.lv/help/kb-tags/ms-sql/"
    - name: "mssql"
      url: "https://www.zone.lv/help/kb-tags/mssql-en/"
    - name: "php"
      url: "https://www.zone.lv/help/kb-tags/php-eng/"
    - name: "sql"
      url: "https://www.zone.lv/help/kb-tags/sql-eng/"
---

# Connecting to MSSQL

In order to connect to MSSQL, you need to activate the **PDO / DBLib** extension under PHP extensions.
To activate PHP extensions, select “Webserver” -&gt; “Main domain settings” and from there select “modify” -&gt; “PHP extensions”.[![](https://www.zone.lv/static/sites/5/main-domain-settings-modify-1024x534.png)](https://www.zone.lv/help/en/kb/connecting-to-mssql/main-domain-settings-modify/)

[![](https://www.zone.lv/static/sites/5/n2-1024x570.png)](https://www.zone.lv/help/en/kb/new-relic-license/n2/)

[ ](https://www.zone.lv/static/sites/5/MSSQL_peadomeeni_satted.png)

Via the extensions menu, enable **`PDO / DBLib`**.[![](https://www.zone.lv/static/sites/5/MSSQL_php_laiendused2.png)](https://www.zone.lv/static/sites/5/MSSQL_php_laiendused2.png)

In order to change the settings for connecting to the MS SQL server, you need to create a new file in the home directory */data0X/virtXXX/* named **.freetds.conf**,
(NB! the file name starts with a dot) with the following contents for example:

```
[ODBC]
host = 123.123.123.123
port = 1234
tds version = 8.0
client charset = UTF-8
mssql.charset = "UTF-8"
```

Sample script for creating an MSSQL connection:

```
$pdo = new PDO('dblib:host=ODBC;dbname=database_name;', 'user', 'pass');
```

Details on how to configure .freetds.conf can be found on the [FreeTDS website.](http://www.freetds.org/userguide/freetdsconf.html)
