Using MSSQL stored procedures with codeigniter

This Msdb Class will help you use MSSQL stored procedures with codeigniter.

Usage:
put this class in your application/library folder and load the class in the usual way:
$this->load->library('msdb');

in model or controller assign the result to a variable. Note the result is an array.

To select data use:
$result = $this->msdb->output('SP_Name', array('Param1'=>1, 'Param2'=>2), 'SELECT');

To execute any other query e.g. insert, update, slot machines online delete…
$result = $this->msdb->output('SP_Name', array('Param1'=>1, 'Param2'=>2), 'EXECUTE');

Sample stored procedure:

Alter Procedure [dbo].[SP_Name]
 @Param1 int, @Param2 varchar(500)
 As
 
 BEGIN
 
 Select
 *
 From
 Table_Name
 Where FieldName1 = @Param1 And FieldName2 = @Param2 
 
 End 
use

printf($result);

in your view to see the returned array

NOTE: When inserting or updating a field with data type TEXT in your table parse the parameter as shown:

$result = $this->msdb->output('SP_Name', array('Param1||'=>1, 'Param2'=>2), 'EXECUTE');

Param1 here is of data type TEXT.

Hope this works for you. If you have any questions please comment to this thread.

Thanks

Resources

Download Msdb

A Web designer and developer. Speaks PHP, Java, Javascript, HTML

2 Responses
  • jitendra patel
    Dec 18, 2014

    this function not working

    jitendra patel Dec 18, 2014
    Reply
  • jitendra patel
    Dec 18, 2014

    it give error Fatal error: Call to undefined function mssql_init() in C:xampphtdocsfindtop10systemlibrariesMsdb.php on line 159

    jitendra patel Dec 18, 2014
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *