As a premise, php and pdo are installed.
At first, install nixODBC-devel
and freetds
and php-odbc
.
$ sudo yum -y install unixODBC-devel
$ sudo yum -y install freetds
$ sudo yum -y install php-odbc
And then, edit /etc/odbcinst.ini
$ sudo vi /etc/odbcinst.ini
[/etc/odbcinst.ini]:
[FreeTDS]
Description = ODBC for FreeTDS
Driver64 = /usr/lib64/libtdsodbc.so
Setup64 = /usr/lib64/libtdsodbc.so
FileUsage = 1
Finally, create an PDO object as follows.
<?php
$host = 'xxx.xxx.xxx.xxx';
$port = '1433';
$dbname = 'database-name';
$username = 'username';
$password = 'password';
$dsn = "odbc:Driver=FreeTDS;" .
"SERVER={$host};PORT={$port};DATABASE={$dbname};" .
"ClientCharset=UTF-8";
$pdo = new \PDO($dsn, $username, $password);
Top comments (1)
Hi! Did you try connect to MSSQL 2000 in PHP7 on Ubuntu?