Mssql_connect php7.1 with ubuntu

I use windows 10 and sql server for my site (I use codeigniter), in windows here is my setup

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '----',
    'username' => '--',
    'password' => '-----',
    'database' => '-----',
    'dbdriver' => 'sqlsrv',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

But now I want to download my site from a local server. My server using ubuntu

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty

when i load my codeigner i get this error

Message: Call to undefined function sqlsrv_connect()

My php version

PHP Version 7.1.10-1+ubuntu14.04.1+deb.sury.org+1

how can i fix this? thanks in addvance. I am using ubuntu not windows .

+4
source share
3 answers

According to the Microsoft tutorial, follow these steps:

1. install the ODBC driver

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-tools.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install mssql-tools
sudo apt-get install unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

2. Get the PHP Sql Server Extension

sudo pecl install sqlsrv pdo_sqlsrv
sudo echo "extension= pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
sudo echo "extension= sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

here is the full tutorial (including installing the db server itself):

textbook

+4
source

I think SQLSRV will include the DLL in the PHP version of Windows.

SQL Server Linux, UnixODBC FreeTDS PDO. , Code Igniter SQL Server.

+1

, , SQL Server PHP. Microsoft github:

Microsoft PHP drivers for SQL Server

I believe that they have instructions for creating Ubuntu 16.04. I noticed that you mentioned that you have Ubuntu 14.04.4 - I have not tried it myself, but it may work.

I had success, however, with ubuntu 14.04 a few years ago using the instructions on this site: RobsPHP , but that was for PHP 5.6

Another useful link in your research: Install SQLSrv (php.net)

+1
source

Source: https://habr.com/ru/post/1688252/


All Articles