MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2013, 10:34 AM
jreis jreis is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 341 jreis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 4 h 46 m 42 sec
Reputation Power: 8
Ms sql trigger to fire a php script

I have an issue I am hoping someone might be able to assist with

I have a ms sql database with a trigger that runs when their is an insert on a specific table. What I am trying to do is when their is a new row inserted to run a php script on the server which is a windows server by the way. the php file writes some data to an external Filemaker database

My issue is I am not to experience with triggers and do not think that the trigger is running the php script. When I execute the trigger manually within microsoft sql server management studio express I get a success message but I don't the the php file is actually being run. I can run the php file manually from the command line and have it successfully insert data into Filemaker

Wondering if I post below my trigger if someone might spot an issue that maybe I am missing? Again this is a windows server but php works fine because I can run the php file from the command line and it inserts the data into Filemaker however if I manually execute the trigger in the ms sql studio express program I get a success but no data makes it to my Filemaker?

Here is my trigger
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER TRIGGER [dbo].[cardholders]
   ON [dbo].[ALARM]
   AFTER INSERT
AS 
BEGIN
DECLARE @CARDPIN VARCHAR(255)
DECLARE @CARDNUMBER VARCHAR(255)
DECLARE @FIRSTNAME VARCHAR(255)
DECLARE @LASTNAME VARCHAR(255)
DECLARE @EVENT_TIMESTAMP VARCHAR(255)
DECLARE @CMD VARCHAR(255)
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
SELECT   @CARDNUMBER=  ALARM.ALARM_CARDNUMBER, 
                    @FIRSTNAME=  ALARM.ALARM_CARDFIRSTNAME, @LASTNAME=ALARM.ALARM_CARDLASTNAME,@EVENT_TIMESTAMP=CONVERT(VARCHAR(23),ALARM.ALARM_DATETIME, 121),@CARDPIN= CARD.CARD_PIN
FROM         ALARM LEFT OUTER JOIN
                      CARD ON CARD.CARD_NUMBER = ALARM.ALARM_CARDNUMBER AND CARD.CARD_DELETED = 'false' where  alarm.alarm_id =(select max(alarm_id) from alarm)

    -- Insert statements for trigger here 
SET @CMD = 'C:\phpfiles>php c:\php\filemakerexport.php "firstname='+@FIRSTNAME+'" "lastname='+@LASTNAME+'" "EventTimestamp='+@EVENT_TIMESTAMP+'" "cardnumber='+@CARDNUMBER+'" "cardpin='+@CARDPIN+'"'

EXEC xp_cmdshell @CMD

END

Reply With Quote
  #2  
Old January 11th, 2013, 08:21 AM
Hoser01 Hoser01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 Hoser01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 57 sec
Reputation Power: 0
I believe your problem is with the CMD executing the trigger.

Code:
SET @CMD = 'C:\phpfiles>php c:\php\filemakerexport.php "firstname='+@FIRSTNAME+'" "lastname='+@LASTNAME+'" "EventTimestamp='+@EVENT_TIMESTAMP+'" "cardnumber='+@CARDNUMBER+'" "cardpin='+@CARDPIN+'"'


Try something along the lines of:
Code:
set @cmd = 'cmd.exe /C "c:\php\filemakerexport.php... ...



You may have to change your working directory first.

Cheers,

Chris

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Ms sql trigger to fire a php script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap