2

How can I run a php script ( to run a REST) command from within an MSSQL trigger?

I need this to run a REST command from a remote webservice just after a user logged in.

1 Answer 1

4

Are you sure you want to do this in the database layer?

Do you want your DB transaction to wait (and hold locks) while your REST request comes back? What happens if your web service is running slowly and times out after 1 minute?

It's possible but again, use with caution.

In SQL Server, there is an extended stored procedure called XP_CMDSHELL which will allow you to run scripts on the command line. http://msdn.microsoft.com/en-us/library/ms175046.aspx

It's disabled by default but you can enable it like so:

EXEC sp_configure 'show advanced options', 1
GO
EXEC sp_configure'xp_cmdshell', 1  
GO

Then in your trigger, you can call your script:

xp_cmdshell 'C:\path\to\php\php.exe -f C:\Path\to\your\script.php'

If you must do this in the database, I would strongly suggest just porting your php script to a .net language and executing it as a CLR stored procedure. That would be much more secure and less likely to cause problems.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for reply, you are right this will hold neck of DB, what do you suggest?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.