Issue executing stored procedure from PHP to a Microsoft SQL SERVER

前端 未结 4 1921
刺人心
刺人心 2021-01-20 17:42

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 sto

4条回答
  •  别那么骄傲
    2021-01-20 18:31

    I've been stumbling with a similar error for some time. The thing is that the execution of the stored rpocedure returned a state code 01000/0, which is not an error but a warning, and still don't know why it's beeing returned.

    Anyway, the thing is that the SP was a simple select, and whenever I runned it with the query tool, the select worked just fine, even invoking this select from php with codeigniter the values where returned correctly, but when I tried to use the stored procedure, it keep failing.

    Finally got it working and the solution was to simply mark to not return warnings as errors. Here's a sample code:

     $sp = "MOBILE_COM_SP_GetCallXXX ?,?,?,?,?,?,?,?,?,? "; //No exec or call needed
    
     //No @ needed.  Codeigniter gets it right either way
     $params = array(
                'PARAM_1' => NULL,
                'PARAM_2' => NULL,
                'PARAM_3' => NULL,
                'PARAM_4' => NULL,
                'PARAM_5' => NULL,
                'PARAM_6' => NULL,
                'PARAM_7' => NULL,
                'PARAM_8' => NULL,
                'PARAM_9' => NULL,
                'PARAM_10' =>NULL);
    
     //Here's the magic...
     sqlsrv_configure('WarningsReturnAsErrors', 0);
    
     //Even if I don't make the connect explicitly, I can configure sqlsrv
     //and get it running using $this->db->query....
    
     $result = $this->db->query($sp,$params);
    

    That's it. Hope it helped

提交回复
热议问题