ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

CodeIgniter and MS SQL server

October 22, 2010 9:51am

Subscribe [3]
  • #1 / Oct 22, 2010 9:51am

    Hello Guys!

    Please help me to compose database.php of Codeigniter if I am using MS SQL Server 2005 express edition, PHP and IIS 7.

    As I searched, mssql driver of codeigniter has some issue. So one has suggested to use sqlsrv driver. This driver is available at:-

    http://www.kaweb.co.uk/wp-content/2008/07/ci_php_sqlsrv.zip

    I have downloaded ci_php_sqlsrv.zip and unzipped and copied under system/database/driver.

    Even then CodeIgniter is not able to connect with mssql server.

    Please please help me to figure it out.

  • #2 / Oct 22, 2010 11:09pm

    pickupman

    1317 posts

    I have connected to MS SQL database using ODBC. Setup a system DSN ODBC connection. Here’s my application/config/database.php

    $db['default']['hostname'] = "UPS_WS_12"; //System DSN name
    $db['default']['username'] = "user"; //DB user name
    $db['default']['password'] = "pass"; //DB pass
    $db['default']['database'] = "";
    $db['default']['dbdriver'] = "odbc";
    $db['default']['dbprefix'] = "";
    $db['default']['pconnect'] = FALSE;
    $db['default']['db_debug'] = TRUE;
    $db['default']['cache_on'] = FALSE;

    I tried using the MSSQL driver to know avail. I guess I wasn’t getting the dsn://string right or something. ODBC is working without a hitch.

  • #3 / Oct 23, 2010 1:47am

    Wow It really Works…. thanks pickupman….

    I am able to connect with SQL Server DB but a simple model_function gives me some syntactical error. the model_function os:-i
      function validateLogin($username, $password)
      {
    $this->db->select('i_user_id');
    $this->db->from('user_master UM');
    $this->db->where('UM.vc_username',$username);
    $this->db->where('UM.vc_password',$password);
    $this->db->where('UM.i_status', 1);
    $this->db->where('UM.isdeleted', 0);
    if($this->db->count_all_results())
    {
    $this->db->select('i_user_id');
    $this->db->from('user_master UM');
    $this->db->where('UM.vc_username',$username);
    $this->db->where('UM.vc_password',$password);
    $this->db->where('UM.i_status', 1);
    $this->db->where('UM.isdeleted', 0);
    return $this->db->get()->row()->i_user_id;
    }
        else
        {
    return false;
    }
      }

    and error on browser:-
    ———————-
    [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ‘)’.

    SELECT COUNT(*) AS numrows FROM (user_master UM) WHERE UM.vc_username = ‘admin’ AND UM.vc_password = ‘admin’ AND UM.i_status = 1 AND UM.isdeleted = 0
    ———————-

    If I modify this query to fire directly in sql server then run good:-
    ————————
    SELECT COUNT(*) AS numrows FROM user_master UM WHERE UM.vc_username = ‘admin’ AND UM.vc_password = ‘admin’ AND UM.i_status = 1 AND UM.isdeleted = 0
    ————————
    (just eliminated the parenthesis in from clause)

    how do I fix this problem via CodeIgniter.

  • #4 / Oct 23, 2010 4:39am

    Well it is bit awkward, But I am answering my own question. hehe 😊

    I have updated function _from_tables($tables) under system/database/odbc/odbc_driver.php.

    remove parenthesis from return statement:-

    Instead of:-
              return ‘(’.implode(’, ‘, $tables).’)’;
    It should be:-
              return implode(’, ‘, $tables);

    That it…

    Thankyou so much pickupman…thankyou so much.

  • #5 / Oct 23, 2010 9:20am

    pickupman

    1317 posts

    Glad you got working. I am not sure why there issues using the mssql driver, but odbc works and that’s fine for me.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases