How to connect to MS SQL Server 2000 in PHP7 PDO on CentOS 7
Noriko Yamamoto
Posted on June 17, 2020
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);
đź’– đź’Ş đź™… đźš©
Noriko Yamamoto
Posted on June 17, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.