[freetds] Output parameters

James K. Lowden jklowden at freetds.org
Wed Apr 23 11:21:32 EDT 2008


Gunther Van Butsele wrote:
> 
> I'm having a problem getting my output parameters returned in PHP from
> an sql server stored procedure. This is the code used, it is fairly
> straightforward:
>  
> $canLogin = 666;
> $websiteID = 2;
> 
> $sp = mssql_init('sp_web_WebsiteEnabled');
> mssql_bind($sp, '@WebsiteID', $websiteID, SQLINT4, false); // INT
> mssql_bind($sp, '@Enabled',   $canLogin,  SQLINT1, true);  // TINYINT
> (OUTPUT)
> mssql_execute($sp);

http://www.freetds.org/faq.html#ms.output.parameters

You might check with a TDSDUMP log that the parameter is being returned. 
Example from src/odbc/unittests/const_param.c:

0000 79 68 60 00 00 ac 0d 00-00 01 38 00 00 00 26 04 |yh`..... ..8...&.|
0010 04 b1 cb 74 00 fe 00 00-e0 00 01 00 00 00       |...t.... ......|

token.c:510:processing result tokens.  marker is  79(RETURNSTATUS)
token.c:645:tds_process_tokens: return status is 24680
util.c:162:Changed query state from READING to PENDING
odbc.c:3253:odbc_process_tokens: tds_process_tokens returned 1
odbc.c:3254:    result_type=4043, TDS_DONE_COUNT=0, TDS_DONE_ERROR=0
convert_tds2sql.c:62:convert_tds2sql: src is 56 dest = -16
token.c:495:tds_process_tokens(0x8056100, 0xbfbff220, 0xbfbff224, 0x6914)
util.c:162:Changed query state from PENDING to READING
token.c:510:processing result tokens.  marker is  ac(PARAM)
token.c:1198:tds_process_param_result(0x8056100, 0x8056158)
token.c:1596:processing result. type = 38(integer-null), varint_size 1
token.c:1617:processing result. column_size 4
token.c:1915:tds_get_data: type 38, varint size 1
token.c:1975:tds_get_data(): wire column size is 4 
util.c:162:Changed query state from READING to PENDING
odbc.c:3253:odbc_process_tokens: tds_process_tokens returned 1
odbc.c:3254:    result_type=4042, TDS_DONE_COUNT=0, TDS_DONE_ERROR=0
convert_tds2sql.c:62:convert_tds2sql: src is 56 dest = -16
token.c:495:tds_process_tokens(0x8056100, 0xbfbff220, 0xbfbff224, 0x6914)
util.c:162:Changed query state from PENDING to READING
token.c:510:processing result tokens.  marker is  fe(DONEPROC)
token.c:2201:tds_process_end: more_results = 0
                was_cancelled = 0
                error = 0
                done_count_valid = 0
token.c:2217:tds_process_end() state set to TDS_IDLE

Memo to file: it would be nice if the output parameter values (and return
status) appeared in the log, so we'd know what the user could expect to
see.  

HTH.  

--jkl




More information about the FreeTDS mailing list