0

I know there are several questions that is similar to this question, but somehow I am not able to get it to work, and I have been going around to check for solution but unfortunately I cant find any:

Situation: I have a web application built in CodeIgniter Framework, at the moment it can save records into its own MySQL Database(DB1), I am also required to create another datalink to another Database which is a MSSQL that will serve as our ledger, lets call that database DB2.

I have tried the:

$active_group = 'default';
$active_record = TRUE;
$db['MSSQL']['hostname'] = 'xxx.xxx.xxx.xxx\SQLEXPRESS';
$db['MSSQL']['port'] = 1433;
$db['MSSQL']['username'] = 'sa';
$db['MSSQL']['password'] = 'xxxxxxxxxxxxxx';
$db['MSSQL']['database'] = 'DB2';
$db['MSSQL']['dbdriver'] = 'mssql';
$db['MSSQL']['dbprefix'] = '';
$db['MSSQL']['pconnect'] = FALSE;
$db['MSSQL']['db_debug'] = TRUE;
$db['MSSQL']['cache_on'] = FALSE;
$db['MSSQL']['cachedir'] = '';
$db['MSSQL']['char_set'] = 'utf8';
$db['MSSQL']['dbcollat'] = 'utf8_general_ci';
$db['MSSQL']['swap_pre'] = '';
$db['MSSQL']['autoinit'] = TRUE;
$db['MSSQL']['stricton'] = FALSE;

$db['default']['hostname'] = '127.0.0.1';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'DB1';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

I can access and get records from the DB1 using this in Model:

class Transaction_model extends CI_Model{
function __construct(){
parent::__construct();}

public function get_transaction(){
$default_db = $this->load->database('default',TRUE);
$qry_res = $default_db->query("CALL sp_view_transaction()");
$res = $qry_res->result();
$qry_res->next_result();
$qry_res->free_result();
$return $res;

class Transaction extends My_Controller{
public function index(){
parent::__construct();}
public function get_transaction(){
$this->load->model('transaction_model');
$result = $this->transaction_model->get_transaction();
print_r($result);

but the problem starts to occur when I am trying to run stored procedure for the MSSQL: Controller: $this->load->model('transaction_model'); $result = $this->transaction_model->MSQL_Transaction(); $print_r($result);

Model:
Public function MSQL_Transaction(){
$db = $this->load->database('MSSQL',TRUE);
$qry = $db->query("EXEC sp_view_list 1");
$res = $qry->result();
$qry->next_result();
$qry->free_result();
return $res;

Anyone can give me advise on what I should do? I need to make an update on DB2 when I have successfully inserted a record in DB1. so far it is only returning empty web page which does not show any error. Thank you very much in advance. I am just showing the select query coz I find it the easiest to understand, if anyone can give me a sample on how it should be done, it will really help alot.

cheers.

rfpdl
  • 956
  • 1
  • 11
  • 35
  • now sql server is connected with sqlsrv so try this page instructions http://php.net/manual/en/book.sqlsrv.php – Sundar Jul 08 '13 at 11:56
  • http://www.php.net/manual/en/intro.mssql.php mssql is not available on PHP5.3 – Sundar Jul 08 '13 at 11:59

2 Answers2

0

Try this configurations before install sqlsrv driver support to your server

<?php 

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'xxxxxxxxxxxxxxxxxx\SQLEXPRESS';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'xxxxxxxxxxxxxx';
$db['default']['database'] = 'database_name';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = FALSE;
$db['default']['stricton'] = FALSE;
Sundar
  • 4,580
  • 6
  • 35
  • 61
  • Thank you for your response, I have to find other way, rather than pushing data using code behind I had to push it using MySQL to MSSQL. – rfpdl Jul 11 '13 at 02:22
0
$active_group = 'default';

$active_record = TRUE;

$db['default']['hostname'] = '1xx.xxx.xx.x6x\SQLEXPRESS';

$db['default']['username'] = 'sa';

$db['default']['password'] = 'password';

$db['default']['database'] = 'databasename';

$db['default']['dbdriver'] = 'mssql';

$db['default']['dbprefix'] = '';

$db['default']['pconnect'] = TRUE;

$db['default']['db_debug'] = TRUE;

$db['default']['cache_on'] = FALSE;

$db['default']['cachedir'] = '';

$db['default']['char_set'] = 'utf8';

$db['default']['dbcollat'] = 'utf8_general_ci';

$db['default']['swap_pre'] = '';

$db['default']['autoinit'] = TRUE;

$db['default']['stricton'] = FALSE;
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
FAISAL
  • 350
  • 3
  • 4