1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Connecting 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) in SSL - specify this when establishing the connection
- MySQL port 3306 is closed by default - to open it, refer to this guide
- Infomaniak does not install PDO_DBLIB
Prerequisites
- Access to the PHP Extensions menu from the administration console of your Cloud Server (if not, it will be necessary to upgrade the Cloud Server)
Installing PHP_PDO_ODBC
You can install the PHP_PDO_ODBC extension from the PHP Extensions menu of your Cloud Server:
- Log in to the Infomaniak Manager (manager.infomaniak.com) from a web browser like Brave or Firefox
- Click on the icon at the top right of the interface (or navigate through the left sidebar menu)
- Choose Cloud Server (Web & Domain universe)
- Click on the name of the relevant object in the displayed table
- Click on PHP Extensions in the left sidebar menu
- Click on the blue Install an extension button
- Choose the PHP_PDO_ODBC extension
- Confirm the installation
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 .odbc.ini
or in the user's home directory ~~/.odbc.ini or dynamically in PHP code. For example, with the previously defined FreeTDS driver, the driver version 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');