Welcome Guest, Not a member yet? Register   Sign In
Using MSSQL stored procedures with codeigniter
#2

[eluser]vinuf666[/eluser]
[quote author="noadek" date="1319128527"]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:
Code:
$this->load->library('msdb');

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

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

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

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

use
Code:
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:
Code:
$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,
@Email: [email protected], [email protected]

Download link: http://www.4shared.com/file/FIXtHIOB/Msdb.html
[/quote]

Hi guys,

I get this error
Code:
"Fatal error: Call to undefined function mssql_init() in C:\wamp\www\dev\application\libraries\Msdb.php on line 159"


When I try to execute an SP. Its a test DB on localhost and I'm using the admin account.

DB Config is given below:
Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'pa55w0rd';
$db['default']['database'] = 'VM_UI';
$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;

...and how do I call stored procedures which do not have arguments ?? (EXEC sys.sp_whoWink

Thanks in advance guys ! Its a wonderful library


Messages In This Thread
Using MSSQL stored procedures with codeigniter - by El Forum - 10-20-2011, 09:35 AM
Using MSSQL stored procedures with codeigniter - by El Forum - 06-06-2013, 09:10 AM
Using MSSQL stored procedures with codeigniter - by El Forum - 06-06-2013, 02:55 PM
Using MSSQL stored procedures with codeigniter - by El Forum - 06-27-2013, 03:24 AM
Using MSSQL stored procedures with codeigniter - by El Forum - 07-10-2014, 08:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB