• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a stored procedure with sqlsrv vs mssql driver needs "EXEC " prefix

Just posting this here for people scratching their head when moving from mssql driver to sqlsrv driver.

if you are calling a stored procedure e.g.

$this->db->query('get_data @parameter=?', $parameter)

this works under mssql driver
when using sql driver you should change it to

$this->db->query('EXEC get_data @parameter=?', $parameter)

otherwise you get num_rows=-1 and no results

Seems like it would be better practice to extend the db driver to standardize the calling of stored procs.

Reference: https://forum.codeigniter.com/thread-685...#pid345512

File: application/libraries/MY_DB_mssql_driver.php
PHP Code:
class MY_DB_mssql_driver extends CI_DB_mssql_driver {
    public function 
stored_proc($param) {
$this->query('get_data @parameter=?'$param);

File: application/libraries/MY_DB_sqlsrv_driver.php
PHP Code:
class MY_DB_sqlsrv_driver extends CI_DB_sqlsrv_driver {
    public function 
stored_proc($param) {
$this->query('EXEC get_data @parameter=?'$param);


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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