在PHP中呼叫MS SQL預存程序
functiongenerateDocCode(){ $wf_id=self::WORKFLOW_ID; $doc_code=""; $link=mssql_connect($this->cfg->db->params->host,$this->cfg->db->params->username,$this->cfg->db->params->password)ordie("Can'tconnectsqlserver"); mssql_select_db($this->cfg->db->params->dbname,$link)ordie("Selectdatabasefailure"); $stmt=mssql_init("GenerateDocCode",$link)ordie("initializestoredprocedurefailure"); mssql_bind($stmt,"@wf_id",$wf_id,SQLINT4); mssql_bind($stmt,"@doc_code",$doc_code,SQLVARCHAR,true); mssql_execute($stmt,false); //print"DocCodeis:".$doc_code; return$doc_code; }
先呼叫mssql_init語句用於初始化預存程序,而後呼叫mssql_bind語句指定預存程序參數,最後呼叫mssql_execute執行預存程序。