简体   繁体   中英

I need to connect SQL SERVER to my codeigniter project

No it's not a Duplicate. In that also they said to include dll files. I did it but still I got same error

I need to connect sql server to codeigniter project. And I added

extension = php_sqlsrv_56_ts.dll in php.ini

But still I got fatal Error.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'ADMIN-PC\SQLEXPRESS',
    'username' => 'name',
    'password' => 'password',
    'database' => 'dbname',
    '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
);

This is what I got while run this on localhost (Appache Server)

Fatal error: Call to undefined function sqlsrv_connect() in C:\\xampp\\htdocs\\MyProject\\system\\database\\drivers\\sqlsrv\\sqlsrv_driver.php on line 144

A PHP Error was encountered Severity: Error

Message: Call to undefined function sqlsrv_connect()

Filename: sqlsrv/sqlsrv_driver.php

Line Number: 144

Backtrace:

After many attempts I finally find solution.

All you need to follow below steps.

Step 1: Find version of your php by using php_info().

Step 2 : You have to find exact sqlsrv compiler (which means the .dll file) for your php version.

Eg : if you are using php 7.1 then the exact compiler is php_sqlsrv_71_ts.dll
like if you using php 5.6 then it should be php_sqlsrv_56_ts.dll

Step 3 : Add this in your xampp/php/ext folder

Step 4 : Then add this line in your php.ini file extension=php_sqlsrv_71_ts_.dll

Step 5 : Now stop and start Apache server.

Now You can find sqlsrv in php_info().

if you didn't find then you should check error log.

That's all Thank you folks :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM