Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Connect a Cloud Server to an external database

This guide explains how to connect to an external database from a Cloud Server.

 

Preamble

  • It is possible to connect to MySQL (external or not) via SSL - to be specified when establishing the connection.
  • The MySQL port 3306 is closed by default - to open it, refer to this other guide.
  • Infomaniak does not install PDO_DBLIB.

 

Install PHP_PDO_ODBC

Prerequisites

It is possible to install the PHP_PDO_ODBC extension from the PHP Extensions menu of your Cloud Server:

  1. Click here to access the management of your product on the Infomaniak Manager (need help?).
  2. Click directly on the name assigned to the product concerned.
  3. Click on PHP Extensions in the left sidebar.
  4. Click on the blue button Install an extension.
  5. Choose the PHP_PDO_ODBC extension.
  6. Confirm the installation.

 

Configure the connector

The driver configuration is already defined in /etc/odbcinst.ini:

[FreeTDS]
Description = MS SQL database access with Free TDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

There is no need to redefine it statically in the .odbc.ini or in the user's home ~~/.odbc.ini~~ or also dynamically in the PHP code.

Example with the FreeTDS driver defined in advance, the version of the driver must also be specified at the end of the pdo object declaration:

$con = new PDO('odbc:Driver=FreeTDS;Server=__SERVER IP__;Port=3306;DATABASE=__DATABASE NAME__;UID=__USERNAME__;PWD=__PASSWORD__;TDS_Version=8.0');

Has this FAQ been helpful?