1

Currently my project is running on

XAMPP Version 1.7.3
Codeigniter Version 2.1.4
SQL-Server - Microsoft SQL Server 2012 (SP4-GDR) (KB4057116) - 11.0.7462.6 (X64)

It was running fine but the database is growing day by day and the performance is also getting slower in the same manner. Besides that, due to few other major concerns we are forced to migrate to SQL-Server. Now the database is completely migrated to SQL-Server from MySQL.

The problem is in the connection Codeigniter -> SQL-Server while using XAMPP server. I have tried so many codes that is found in the google but none of these working. One I have is

$active_group = 'default'; 
$query_builder = TRUE; 
$db['default'] = array( 
'dsn'   => '', 
'hostname' => 'MSSQLSERVER', 
'username' => '', 
'password' => '', 
'database' => 'test',  --changed
'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 
);

I am a database developer so couldn't make any additions to the code due to lack of ideas. So, can you plese share your ideas to resolve this problem. I am expecting it in detail steps. It’s no problem If I need to upgrade my versions or change anything else, but I can't change the framework itself.

3
  • Can you check PHP config if the mssql support is enabled? also, you'll have to update the DNS part of the db config to point to your mssql server. i.e 'dsn' => 'dblib:dbname=biometric;host=BIOSQL\SQL', Commented Jun 26, 2018 at 5:02
  • Where do I find PHP config and can I use exactly 'dsn' => 'dblib:dbname=biometric;host=BIOSQL\SQL' without any change ? Commented Jun 26, 2018 at 5:06
  • 1
    you can add phpinfo(); to any viewable page. php.net/manual/en/function.phpinfo.php. That's our own db name and host so you'll have to update that to fit your current setup. Commented Jun 26, 2018 at 5:07

1 Answer 1

1
+50

This process was bit easier for me but being a database developer, it gonna bit harder for you. No worries, if you follow the instructions properly then it will work in a single shot

1- Setup CI configuration files and other setup from the following link

https://futbolsalas15.wordpress.com/2014/02/23/7-steps-to-make-sql-server-and-codeigniter-works/

After doing the above changes, It will still remain incomplete in my case and I did the below additional changes

IN FILE: system\database\DB.php

require_once(BASEPATH.'database/DB_driver.php'); --Find this line
$active_record=TRUE;    --Add this line below

IN FILE: system\database\DB_driver.php

var $dbdriver = 'mysql'; --Replace `mysql` with `sqlsrv`

SP calling method, suppose you have sp_report with four parameters as below:

--From Mysql
$call_proc = "CALL sp_report('b', 'a', $date_from, $date_to)"

--From SQLServer
$call_proc = "DECLARE @p_report_type CHAR(1) = 'b',
    @p_sub_type CHAR(1) = 'a',
    @p_date_from VARCHAR(10) = '".$date_from."',
    @p_date_to VARCHAR(10) = '".$date_to."'

    EXEC sp_report @p_report_type, @p_sub_type, @p_date_from, @p_date_to"

Thats all my friend, hope it will work as expected.

Sign up to request clarification or add additional context in comments.

1 Comment

It's seems working fine, doing changes in the calling method but the connection is absolutely fine. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.