Manage connection to MsSQL database from your Symfony2 project
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DependencyInjection
Resources/config
Service
MssqlBundle.php
README.md

README.md

This bundle gives you a Symfony2 service to connect to MsSQL database.

  • The abastraction layer is taken from the class dibi by David Grudl - http://dibiphp.com
  • I've added getResultResourceIterable method so you can easly iterate on resultset using for in TWIG.
  • You need to install and configure FreeTDS and php5-sybase module on your server.

Installation

Add DeployBundle to your deps

[HpatoioMssqlBundle]
  git=git://github.com/hpatoio/MssqlBundle.git
  target=/bundles/Hpatoio/MssqlBundle

Add DeployBundle to your application kernel

<?php
	// app/AppKernel.php
	public function registerBundles()
	{
		return array(
			// ...
			new Hpatoio\MssqlBundle\MssqlBundle(),
			// ...
		);
	}

Register the namespace in autoload.php

'Hpatoio'     => __DIR__.'/../vendor/bundles',

Configure

# app/config/config.yml
mssql:
  username: mssql_username
  password: mssql_password
  dbname: mssql_dbname
  host: mssql_host

Use

<?php
	public function demoAction()
	{
		$mssql_db	= $this->get('hpatoio_mssql.db_connector');
		$mssql_db->query("SELECT * FROM mytable");
		
		// Iterable object
		$iterable_rs  	= $mssql_db->getResultResourceIterable();
	    
		return array(
			'testate_rs'   	=> iterable_rs,
		);
	}