Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mssql_connect php7.1 with ubuntu

I'm using Windows 10 and SQL Server for my website (I'm using codeigniter), in Windows here is my setting

$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 upload my site from local to my server. My server using ubuntu

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

When I upload my codeigniter, 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 it? Thanks in advance.

I'm using ubuntu - not Windows

like image 660
YVS1102 Avatar asked Mar 07 '23 17:03

YVS1102


1 Answers

as per microsoft's tutorial, the steps are:

1. install 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 PHP Sql Server extention

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):

tutorial

like image 172
am05mhz Avatar answered Mar 10 '23 07:03

am05mhz