Error trying to connect to SQL Server with CodeIgniter and PHP 7

1

Good afternoon, I started having problems with my CI when upgrading my development environment (windows + xammp) and production (ubuntu + apache) to the latest version of PHP 7.1.10.

When trying to connect to Microsoft SQL Server I get the following message:

  

An uncaught Exception was encountered Type: Error Message: Call to   undefined function mssql_connect () Filename:   C: \ xampp \ htdocs \ psa \ system \ database \ drivers \ mssql \ mssql_driver.php   Line Number: 113 Backtrace: File: C: \ xampp \ htdocs \ psa \ index.php Line:   315 Function: require_once

I have already downloaded the latest drives on the Microsoft website, and I followed some examples, but I still have the same problem.

My php.info returns me that SQL Server support is enabled.

  

Registered PHP Streams php, file, glob, date, http, ftp, zip,   compress.zlib, compress.bzip2, https, ftps, sqlsrv, phar

     

PDO support enabled

     

PDO drivers mysql, sqlite, sqlsrv

     

pdo_sqlsrv support enabled

     

ExtensionView 4.3.0 + 9904

If someone has already had the same problem and has already managed to solve it, and want to tell us their experience, thank you in advance.

    
asked by anonymous 07.05.2018 / 22:00

2 answers

1

I'm sorry to inform you, but the mssql_connect() function has been removed from PHP 7.0.0 as you can check in here .

Now you should use alternate functions like sqlsrv_connect () or odbc_connect .

    
07.05.2018 / 22:11
0

Would anyone have an example CodeIgniter configuration to connect to SQL Server using PHP7?

Using the odbc or sqlsrv drive since mssql has been deprecated.

This example did not work.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '192.168.0.5',
    'username' => 'usuario',
    'password' => 'senha',
    'database' => 'nome_banco',
    '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
);

Thank you in advance.

    
16.05.2018 / 15:35