views:

32

answers:

1

I'm working on a web app that is using PHP and MSSQL. One of my requirements is to use the field descriptions in MSSQL in part of the web app.

I know the Stored Proc. for adding descriptions in MSSQL is:

EXEC sp_addextendedproperty 
@name = N'Description', @value = 'Description goes here',
@level0type = N'Schema', @level0name = 'schemaname',
@level1type = N'Table',  @level1name = 'tablename',
@level2type = N'Column', @level2name = 'columname'
GO

I am having problems converting this into php, however.

I'm trying to use the mssql_init/bind/execute commands, but I keep getting an error that I am not sure how to troubleshoot.

PHP Code:

$query = mssql_init("sp_addextendedproperty",$dblink);
mssql_bind($query,"@name","N'Description'",SQLVARCHAR);
mssql_bind($query,"@value",$_POST['description'],SQLVARCHAR);
mssql_bind($query,"@level0type","N'Schema'",SQLVARCHAR);
mssql_bind($query,"@level0name","dbo",SQLVARCHAR);
mssql_bind($query,"@level1type","N'Table'",SQLVARCHAR);
mssql_bind($query,"@level1name",$_POST['tableselect'],SQLVARCHAR);
mssql_bind($query,"@level2type","N'Column'",SQLVARCHAR);
mssql_bind($query,"@level1name",$_POST['column_name'],SQLVARCHAR);
mssql_execute($query)

My error is:

An invalid parameter or option was specified for procedure 'sp_addextendedproperty'. (severity 16)

I don't know enough about stored procedures to fully troubleshoot this. Can somebody help me out?

+1  A: 

Unless you've simply made a typo posting your sample code, you're using @level1name twice. The second occurrence should be @level2name instead.

Joe Stefanelli
@Joe, thanks for catching that, I have been looking at this too long. I updated the code but it's still not correct, giving me the same error.
mcfrosty
Try leaving the "N" off of the 'Schema', 'Table' and 'Column' level type parameters perhaps?
Joe Stefanelli
That still isn't doing it. is there a good way to troubleshoot/log stuff going to MSSQL Stored Procs?
mcfrosty