4

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
YVS1102
  • 2,658
  • 5
  • 34
  • 63
  • 1
    @Dalton , I don't think that it is a duplicate. The other thread is for Windows vs this one trying to access sqlsrv on Debian Ubuntu 14. – Navid Oct 29 '17 at 23:46
  • @YVS1102 , do you have ssh access to the server? Can you check existence of sqlsrv and pdo_sqlsrv modules? You can run `php -m` and check the list of php modules. Also, can you determine if PECL is installed on your server? – Navid Oct 29 '17 at 23:50

3 Answers3

5

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

Community
  • 1
  • 1
am05mhz
  • 2,727
  • 2
  • 23
  • 37
1

I think that 'SQLSRV' will incorporate the DLL into the Windows version of PHP.

If you want to connect to SQL Server on Linux, install UnixODBC and FreeTDS and connect with PDO. Actually, I am using Code Igniter and SQL Server.

chatii
  • 53
  • 1
  • 4
1

What you'll want to do is make sure that you have the proper SQL Server driver for PHP. Microsoft has a driver available on github:

Microsoft PHP Drivers for SQL Server

I believe they have instructions on building for Ubuntu 16.04. I noticed you mentioned that you have Ubuntu 14.04.4 - I haven't tried it myself but it may work.

I did have success however with ubuntu 14.04 a few years back using the instructions on this site: RobsPHP but this was for PHP 5.6

Another possibly helpful link in your research: SQLSrv installation (php.net)

YourWebDevGuy
  • 73
  • 1
  • 8