17275

How to execute a MSSQL stored procedure with ADOdb PHP Library?

Question:

I've followed the instructions in the <a href="http://phplens.com/lens/adodb/docs-adodb.htm#preparesp" rel="nofollow">ADOdb documentation</a> and I'm trying to execute a stored procedure on a sql server 2008 database like so:

$stmt = $db->PrepareSP('usp_insert_aweber_list'); $db->InParameter($stmt,$id,'List_ID',false,SQLINT4); $db->InParameter($stmt,$name,'Name',255,SQLVARCHAR); $db->InParameter($stmt,$campaigns_collection_link,'Campaign_Collections_Link',255,SQLVARCHAR); $db->InParameter($stmt,$custom_fields_collection_link,'Custom_Fields_Collection_Link',255,SQLVARCHAR); $db->InParameter($stmt,$http_etag,'HTTP_Etag',255,SQLVARCHAR); $db->InParameter($stmt,$resource_type_link,'Resource_Type_Link',255,SQLVARCHAR); $db->InParameter($stmt,$self_link,'Self_Link',255,SQLVARCHAR); $db->InParameter($stmt,$subscribers_collection_link,'Subscribers_Collection_Link',255,SQLVARCHAR); $db->InParameter($stmt,$total_subscribers,'Total_Subscribers',false,SQLINT4); $db->InParameter($stmt,$total_subscribed_subscribers,'Total_Subscribed_Subscribers',false,SQLINT4); $db->InParameter($stmt,$total_subscribers_subscribed_today,'Total_Subscribers_Subscribed_Today',false,SQLINT4); $db->InParameter($stmt,$total_subscribers_subscribed_yesterday,'Total_Subscribers_Subscribed_Yesterday',false,SQLINT4); $db->InParameter($stmt,$total_unconfirmed_subscribers,'Total_Unconfirmed_Subscribers',false,SQLINT4); $db->InParameter($stmt,$total_unsubscribed_subscribers,'Total_Unsubscribed_Subscribers',false,SQLINT4); $db->InParameter($stmt,$web_form_split_tests_collection_link,'Web_Form_Split_Tests_Collection_Link',255,SQLVARCHAR); $db->InParameter($stmt,$web_forms_collection_link,'Web_Forms_Collection_Link',255,SQLVARCHAR); $rs = $db->Execute($stmt); if (!$rs){ print $db->ErrorMsg(); echo '<br /><br />'; }

The above bit of code just outputs the following error message:

[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function 'usp_insert_aweber_list' expects parameter '@List_ID', which was not supplied.

I've believe I've provided the List_ID param in my first $db->InParameter() call. Correct me if I'm wrong. Before any responds with 'Add an @ in front of the param name' the documentation notes it's not needed and I've tried it already and it results in the same error message.

Thanks

Answer1:

I just looked into ADOdb 5.13 (and 5.14 & 5.15 changelog does not mention any changes in that area) code and it seems that ODBC driver for MSSQL does not support binding parameters to the prepared statements and does not produce any error while you are trying to do it.

Answer2:

I've seen this working against earlier versions of SQL Server, but only when using the 'mssql' driver (and not odbc_mssql or ado_mssql).

Recommend