반응형
class Example_controller extends CI_Controller {// …// Others attributes and methods omitted for brevity/** Unfortunatelly, CodeIgniter does not work well with Stored Procedure with returning parameters,* so, if you want to use any kind of Stored Procedure with parameters, it's better do it mannualy.*/public function some_function($parameter1, $parameter2){// Connect to DB. You can't pass $this->db, cause it's an object and the connection info// needs and Connection resource.$serverName = "10.5.6.11";$connectionInfo = array( "Database"=>"databasename", "UID"=>"username", "PWD"=>"secretword");$conn = sqlsrv_connect( $serverName, $connectionInfo);if( $conn === false ) {die( print_r( sqlsrv_errors(), true));}/* Define the Transact-SQL query. Use question marks in place ofthe parameters to be passed to the stored procedure */$tsql_callSP = "{call zp_contas_receber_inc_congresso(?, ?, ?)}";/** Define the parameter array. Put all parameter in the order they appear in the SP.* The second argument is needed to say if the parameter is an INPUT or an OUTPUT*/// This must be set as Integer, cause the initial type for the OUTPUT$output_parameter = 0;$params = array(array($parameter1, SQLSRV_PARAM_IN),array($parameter2, SQLSRV_PARAM_IN),array($output_parameter, SQLSRV_PARAM_OUT));/* Execute the query. */$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);if( $stmt === false ){echo "Error in executing statement.\n";die( print_r( sqlsrv_errors(), true));}/*Free the statement and connection resources. */sqlsrv_free_stmt($stmt);return $output_parameter;}}
반응형
'Development > PHP' 카테고리의 다른 글
PDO - PHP Data Object (0) | 2013.07.02 |
---|---|
SQL Server Driver - Case 2 <미테스트> (0) | 2013.06.21 |
IIS7 PHP 이클립스 디버깅 (0) | 2013.06.21 |
gzip 인코딩 압축 전송 사용하기 (0) | 2013.05.29 |
IIS7 에서 CodeIgniter index.php 제거 하기 (0) | 2013.02.20 |
댓글