PHP 7.3 PDO sqlsrv on CentOS 7
Sometimes you need old-school setups… Here is how to use PDO sqlsrv for PHP 7.3 on CentOS 7.
Example usage
$mssql = new PDO('sqlsrv:database=$database;server=$server,$port', $username, $password);
First – a pleasant surprise from Microsoft: good documentation and no broken links. Respect!
Install PHP 7.3 and SQLSRV drivers
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
ACCEPT_EULA=Y yum install -y epel-release msodbcsql17 mssql-tools unixODBC-devel php-pear php-devel
pecl channel-update pecl.php.net
pecl install sqlsrv pdo_sqlsrv
Enable extensions in PHP
echo "extension=pdo_sqlsrv.so" >> /etc/php.d/30-pdo_sqlsrv.ini
echo "extension=sqlsrv.so" >> /etc/php.d/30-pdo_sqlsrv.ini
Verify installation
# php -i | grep -i sqlsrv
/etc/php.d/30-pdo_sqlsrv.ini,
Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, sqlsrv, zip
PDO drivers => dblib, mysql, sqlite, sqlsrv
pdo_sqlsrv
pdo_sqlsrv support => enabled
pdo_sqlsrv.client_buffer_max_kb_size => 10240 => 10240
pdo_sqlsrv.log_severity => 0 => 0
sqlsrv
sqlsrv support => enabled
sqlsrv.ClientBufferMaxKBSize => 10240 => 10240
sqlsrv.LogSeverity => 0 => 0
sqlsrv.LogSubsystems => 0 => 0
sqlsrv.WarningsReturnAsErrors => On => On
And that’s all – it works fine.
Human Logic, AI Syntax...
Note on Content: I'm a Systems Engineer, not a native English writer. To ensure my technical ideas are clear and accessible, I use AI tools to polish the grammar and style. The workflow is simple: I provide the logic, the code, and the real-world experience. The AI handles the "English-to-Human" translation layer. If you find a bug, that's on me. If you find a perfectly placed comma, that's probably the AI.
Comments
Post a Comment