I currently have a PHP script developed to update product dimensions on my company’s website. We have all of our products stored in a database. The data is Selected from the database and put into a PUT request to update the products using PHP. My program is working as intended but I am looking to automate the process, so when a product is updated or inserted in the database my PHP script is ran and updates the products on our website. Is it possible to use a SQL trigger to call the URL for my PHP script when records are updated? If not, what is the best to automate the process. I am still pretty new to programming so if I need to share any more information, please let me know!
–I have tried a few different solutions with no luck. Currently I have a stored procedure that looks like this:
CREATE[dbo].[Proc_CallPHPFromSQL]
as
DECLARE @URL NVARCHAR(MAX) = ‘http://myphpurl.php’;
Declare @Object as Int; — declare object
Declare @ResponseText as Varchar(8000);
Exec sp_OACreate ‘MSXML2.XMLHTTP’, @Object OUT; — creating OLE object and assigning it to variable @Object
— passing the @Object created above, with our http call and handling the response with help of sp_OAMethod
Exec sp_OAMethod @Object, ‘open’, NULL, ‘get’,
@URL,
‘False’
Exec sp_OAMethod @Object, ‘send’
Exec sp_OAMethod @Object, ‘responseText’, @ResponseText OUTPUT
–Then I set a trigger to the database that is updated like this:
CREATE TRIGGER run_php
on EXT_Flag
AFTER INSERT, UPDATE
AS
EXEC Proc_CallPhpFromSQL;
Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.