Error when trying to connect to SQL Server with Codeigniter and PHP 7

Asked

Viewed 326 times

1

Good afternoon, I started having problems with my CI when updating 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 already downloaded the latest drives on the Microsoft site, and followed a few examples, but I still have the same problem.

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

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

PDO support enabled

PDO drivers mysql, sqlite, sqlsrv

pdo_sqlsrv support enabled

Extensionver 4.3.0+9904

If someone has been through the same problem and has already been able to solve, and you want to tell us your experience, I thank you.

  • http://php.net/manual/en/mssql.installation.php

2 answers

1

I’m sorry to inform you, but the function mssql_connect() was removed from the PHP 7.0.0 how it is possible to check in the manual here.

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

  • Good afternoon, thanks in advance. You would have an example of how to configure Codeigniter with these settings?

0

Someone would have an example of Codeigniter configuration to connect to SQL Server using PHP7?

Using odbc or sqlsrv drive since mssql has been discontinued.

That example didn’t 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
);

Thanks in advance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.