MSSQL extension for PHP7 (CWP control web panel)

The SQLSRV extension allows you to access Microsoft SQL Server and SQL Azure databases when running PHP on Windows. 

Follow this easy steps to install and connect MSSQL with sqlsrv and php :

Remove all unixODBC packages before proceeding.

Command ex:

yum remove unixODBC*

# CentOS 6

curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo

# CentOS 7

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

# Installing Microsoft ODBC Driver :

This packages provides an ODBC driver that can connect to Microsoft SQL Server.

ACCEPT_EULA=Y yum install msodbcsql17 unixODBC unixODBC-devel

# After the above installation go to php switcher/selector/php-fpm selector and build the php 7.xx with sqlsrv, you can enable sqlsrv from PHP "Options"

TO check the connection to MSSQL use this php script

Example:

<?php

$serverName = "your server hostname/IP, port";

$connectionOptions = array(

  "database" => "yourDatabase",

  "uid" => "yourUsername",

  "pwd" => "yourPassword"

);


// Establishes the connection

$conn = sqlsrv_connect($serverName, $connectionOptions);

if ($conn === false) {

  die(formatErrors(sqlsrv_errors()));

}else{

echo "Successfully connected";

}

Sign In or Register to comment.