Using MSSQL stored procedures with codeigniter |
[eluser]Unknown[/eluser]
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] use Code: printf($result); 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: noadek@yahoo.co.uk, [email protected] Download link: http://www.4shared.com/file/FIXtHIOB/Msdb.html
[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] use Code: printf($result); 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: noadek@yahoo.co.uk, [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'; ...and how do I call stored procedures which do not have arguments ?? (EXEC sys.sp_who Thanks in advance guys ! Its a wonderful library
[eluser]Unknown[/eluser]
If you're using WAMP, make sure that the mssql module is enabled. It will have a checkmark next to its name in the context menu if it is. To call stored procedures which do not have arguments, just pass an empty array.
[eluser]vinuf666[/eluser]
I thought I'll share this piece of code that I made for the MS SQL stored procedures if anyone uses 'sqlsrv' as the driver platform instead of mssql in codeIgniter sqlsrv is quite buggy but is the latest Microsoft SQL server driver for php. You need to create the model as follows Code: class SPTest extends CI_Model { The stored Procedure sample structure we are using here is Code: ALTER PROCEDURE [dbo].[TestSP] In the controller class you can send the IN, OUT variables like this Code: public function index2() type issues (float int..) in case of numbers. The view just dumps the variable like this echo var_dump($sprdata); I hunted a long way to get this to work as the mssql did not work with my WAMP installation due to missing dll. Hope this info helps someone who is stuck with this issue.
[eluser]mariepizzer[/eluser]
Hello, your code has been really useful. Thank you so much! [quote author="vinuf666" date="1372328663"]I thought I'll share this piece of code that I made for the MS SQL stored procedures if anyone uses 'sqlsrv' as the driver platform instead of mssql in codeIgniter sqlsrv is quite buggy but is the latest Microsoft SQL server driver for php. [/quote] |
Welcome Guest, Not a member yet? Register Sign In |