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

#1
Bug 
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
Reply

#2
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) {
        return 
$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) {
        return 
$this->query('EXEC get_data @parameter=?'$param);
    }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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