Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue executing stored procedure from PHP to a Microsoft SQL SERVER

I am using the code igniter framework. And I been trying to execute a stored procedure(no params) I wrote on Microsoft SQL Server 2008 from PHP but i get an error . This stored procedure runs good on Microsoft SQL Server with no errors. I am using sqlsrv as the driver and I have a PHP version 5.2 if that helps.

This is the error I get

Error Number: 01000
[Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor
Exec sp_test

The following is part of the code I have

function index(){
  $this->load->database();
  $query=$this->db->query("Exec sp_test");
  var_dump($query->result());
}

I replace the actual query with an actual query and it does work but not with a sp call. Any help will be appreciated, I tried for so long on this and i can't get it to work. Thanks

like image 319
user3547086 Avatar asked May 06 '26 19:05

user3547086


1 Answers

I had faced the same issue. Removing the 'EXEC' worked for me.

$query = $this->db->query("procedure_name parameter_1, parameter_2");

like image 50
Suhail Avatar answered May 09 '26 09:05

Suhail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!