EllisLab text mark
Advanced Search
     
sqlsrv-driver in CI 2.1.0
Posted: 24 November 2011 04:29 AM
Joined: 2011-08-26
3 posts

there are some problems while connecting CI 2.1.0 to Microsoft SQL-Server. The driver have some errors and did not return the correct value when trying in pconnect.

Perhaps you can try this patched driver:

 
Posted: 03 January 2012 03:38 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2010-06-28
8 posts

thank you,it what was i need.
tell me, what is wrong in original ci driver?

 
Posted: 30 January 2012 01:03 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-01-24
10 posts

Thanks, Dumbledore.

That has saved me heaps of time.  Has this new code been submitted to the development team for incorporation into CodeIgniter?

I downloaded CI 2.1.0 on Friday, and the connect still does not work without the supplied fix - copy the files to system/database/drivers/sqlsrv.

For example purposes, this is what worked for me in database.php ..

$active_group 'dwh';

/* SQL Server - data warehouse - read */
$db['dwh']['hostname''maittestsql\testsql2008';
// $db['dwh']['hostname'] = 'maittestsql';
// $db['dwh']['port']     = 2646;        // no good - use server/instance instead
$db['dwh']['username''dwh';
$db['dwh']['password''password';
$db['dwh']['database''mydb';
$db['dwh']['dbdriver''sqlsrv';
$db['dwh']['dbprefix''';
$db['dwh']['pconnect'TRUE;
$db['dwh']['db_debug'TRUE;
$db['dwh']['cache_on'FALSE;
$db['dwh']['cachedir''';
$db['dwh']['char_set''utf8';
$db['dwh']['dbcollat''utf8_general_ci';
$db['dwh']['swap_pre''';
$db['dwh']['autoinit'TRUE;
$db['dwh']['stricton'FALSE

 

 
Posted: 06 February 2012 10:26 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2012-02-06
3 posts

Thanks for your work!

Does it require to install some others applications to make it work?

My server is actually running a Debian distribution…

Thanks for your help.

Fanch

 
Posted: 06 February 2012 04:51 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-01-24
10 posts

I used the ‘sqlsrv’ driver supplied by Microsoft.
http://www.microsoft.com/download/en/confirmation.aspx?id=17308 (version 3)
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20098 (version 2)

These are .dll files, though, so presumably this is only available for Windows.

Maybe go for the ‘mssql’ drivers on Debian ?

 
Posted: 07 February 2012 12:47 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2012-02-06
3 posts

Thanks Tybion,

I’ve had to install sybase and freedts (i’m running PHP Version 5.3.6-13ubuntu3.3):

sudo apt-get install libsybdb5 freetds-common php5-sybase
sudo 
/etc/init.d/apache2 restart 

Once installed you can check in phpinfo() answers that the installation was effective.

Thanks to all for your brillant work, CodeIgniter rules!

 
Posted: 21 May 2012 07:42 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-04-07
6 posts

I’m having trouble getting this to work.

My setup is:
Codeigniter 2.1.0
IIS 7.5 w/ PHP FastCGI
SQL Server 2008 (not on web server)

I’m in a situation where I have to use Windows Authentication. I’ve verified that PHP/CI has access to the Windows user identity (printing out $_SERVER[‘REMOTE_USER’] gives correct result). I can connect to the database using the sqlsrv driver directly using this code in my config/database.php:

$serverName $db[ENVIRONMENT]['hostname']//serverName\instanceName

 // Since UID and PWD are not specified in the $connectionInfo array,
 // The connection will be attempted using Windows Authentication.
 
$connectionInfo = array( 'Database' => $db[ENVIRONMENT]['database']);
 
$conn sqlsrv_connect$serverName$connectionInfo );

 if ( 
$conn {
  
echo "Connection established.<br />";
 
}
 
else {
  
echo "Connection could not be established.<br />";
  die ( 
print_rsqlsrv_errors(), true));
 

results in success.

But when I use the sqlsrv driver in CI with the exact same config I get “Unable to connect to your database server using the provided settings.”

I made the fix mentioned in another post (http://ellislab.com/forums/viewthread/197527/) to sqlsrv_driver.php - the zip file file above doesn’t seem to be there anymore, so I don’t know if there’s another bug in the provided driver.

Any ideas?

 
Posted: 23 May 2012 03:27 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2012-05-22
1 posts

I’m not able to access the zip file above too.
Anyone can share the file again.
Thanks.

 
Posted: 23 May 2012 06:23 AM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
132 posts

There’s a fix for that in the current develop branch:

https://github.com/EllisLab/CodeIgniter/commit/37e351f1c1bf76758685158630be723e2951c032#system/database/drivers/sqlsrv/sqlsrv_driver.php

 
Posted: 10 June 2012 03:23 AM   [ # 9 ]   [ Rating: 0 ]
Joined: 2012-01-22
8 posts

Well, i just want to shared if u dont want use the sqldrv from MSSQL, u could see this forum:
http://ellislab.com/forums/viewthread/213879/

 Signature 

mobs6 hmmm

 
Posted: 27 June 2012 05:39 AM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2009-03-22
6 posts
Tybion - 30 January 2012 01:03 AM

Thanks, Dumbledore.

That has saved me heaps of time.  Has this new code been submitted to the development team for incorporation into CodeIgniter?

I downloaded CI 2.1.0 on Friday, and the connect still does not work without the supplied fix - copy the files to system/database/drivers/sqlsrv.

For example purposes, this is what worked for me in database.php ..

$active_group 'dwh';

/* SQL Server - data warehouse - read */
$db['dwh']['hostname''maittestsql\testsql2008';
// $db['dwh']['hostname'] = 'maittestsql';
// $db['dwh']['port']     = 2646;        // no good - use server/instance instead
$db['dwh']['username''dwh';
$db['dwh']['password''password';
$db['dwh']['database''mydb';
$db['dwh']['dbdriver''sqlsrv';
$db['dwh']['dbprefix''';
$db['dwh']['pconnect'TRUE;
$db['dwh']['db_debug'TRUE;
$db['dwh']['cache_on'FALSE;
$db['dwh']['cachedir''';
$db['dwh']['char_set''utf8';
$db['dwh']['dbcollat''utf8_general_ci';
$db['dwh']['swap_pre''';
$db['dwh']['autoinit'TRUE;
$db['dwh']['stricton'FALSE

I got it working the following way on windows with wamp server:

1.Download http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20098 (version 2) and copy the extracted files to the php/ext folder.
1.a. activate php_sqlsrv_53_ts_vc6 and vc9 extensions.
2. Edit file: https://github.com/EllisLab/CodeIgniter/commit/37e351f1c1bf76758685158630be723e2951c032#system/database/drivers/sqlsrv/sqlsrv_driver.php
3. In the config quoted above in hostname use double slash between server and instance
$db[‘dwh’][‘hostname’] = ‘maittestsql\testsql2008’; => $db[‘dwh’][‘hostname’] = ‘maittestsql\\testsql2008’;

Hope this helps

 
Posted: 11 July 2012 04:20 AM   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-07-11
1 posts

@Narf, you’re a super-hero!  Replacing the existing db_pconnect function in system/database/drivers/sqlsrv/sqlsrv_driver.php did the trick perfectly. In case anyone else needs it, the function should now read:

function db_pconnect()   {

  $this
->db_connect(TRUE);
  return 
$this->db_connect(TRUE);

 

and db config in application/config/database.php should read something like :

$db['default']['hostname''server\instancename';
$db['default']['username''dbusername';
$db['default']['password''dbpassword';
$db['default']['database''dbname';
$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'TRUE;
$db['default']['stricton'FALSE

I’m using SQL Server 2012 and IIS, and I need my site to work for a long time into the future, so using the sqlsrv driver from Microsoft was the only option.