• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter Reactor and MS SQL Server - How To Guide

After spending the last two days pulling my hair out in an attempt to get CodeIgniter Reactor to work with SQL Server 2005, I finally managed to figure it all out, and I wanted to share the lessons I learned with the CI community in hopes of saving other developers in the same boat a major headache.

The setup I am working with is as follows:

Quote:* Server: Microsoft Windows Server 2003 Enterprise Edition SP2
* Setup: xampp-win32-1.7.5-beta2-VC9
* DB: Microsoft SQL Server 2005 [Developer/Enterprise Edition]
* Framework: CodeIgniter 2.02

The first thing I did after setting up my development environment was to download the SQL for PHP drivers (2.0) from Microsoft: http://sqlsrvphp.codeplex.com/releases/view/31762

After installing the drivers to C:\xampp\php\ext, I then edited my php.ini file to include the appropriate drivers. In my case, being that I was running XAMPP with PHP 5.3, I needed the 5.3 thread safe VC9 drivers, so I added the following lines to PHP.ini:


If you're unsure which SQL drivers you need for your setup, create a phpinfo(); page, and look for this information: PHP Extension Build. Mine is API20090626,TS,VC9. If you see NTS, you'll need the Non Thread Safe drivers, VC6/9 will indicate which version of the driver you'll need.

Once you've added the appropriate lines to your php.ini file, go ahead and restart your server. Check your phpinfo file again to see if sqlsrv is now listed in your Registered PHP Streams. If it's not (or your server won't start), then you may need to install the Microsoft SQL Server 2008 R2 Native Client: http://www.microsoft.com/download/en/det...n&id=16978

After installing that, you should then restart your server, and check your phpinfo file again.

Once you have verified that the sqlsrv drivers are loaded, it's time to get CodeIgniter set up to connect to your database. Open up /application/config/database.php, and enter your host and account information. Make sure that PCONNECT is set to FALSE.

Once you're done setting your database connection up, go ahead and write up a model to connect to your db. If everything worked out, you should be able to connect to your SQL database with ease.

Lastly, I would highly suggest you use a git client, like Mercurial or TortoiseHG to clone Erik Giberti's fork of CI (Pull request submitted a week ago at the time of this writing) here: https://bitbucket.org/ellislab/codeignit...or-windows

If you're new to HG cloning, punch this url into your clone from field to download the fork, including the updated SQLSRV drivers: https://bitbucket.org/giberti/codeigniter-reactor

The updated drivers are in /system/database/drivers/sqlsrv/ - Simply copy over the sqlsrv folder to your CI installation. Make sure that you're using 'sqlsrv' and NOT 'mssql' as your driver in your database config file.

Big thanks to Erik Giberti for his work on the new drivers. They should hopefully be integrated into the main CI branch soon.

I'm no expert, but I'm happy to try to help anyone that needs a little more help with this post.

Happy coding!

Messages In This Thread
CodeIgniter Reactor and MS SQL Server - How To Guide - by El Forum - 07-22-2011, 09:02 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.