pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Triggers, Rules and email
5+ messages / 4 participants
[nested] [flat]

* Triggers, Rules and email
@ 2004-01-20 17:06 Paul <pauljw@truswan.com>
  2004-01-20 17:59 ` Re: Triggers, Rules and email scott.marlowe <scott.marlowe@ihs.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Paul @ 2004-01-20 17:06 UTC (permalink / raw)
  To: pgsql-php

Anyone know if I can create a trigger or a rule in Pgsql that will send 
an email in the event of an attempt to update a database field no-one 
should be updating?

TIA,
Paul



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Triggers, Rules and email
  2004-01-20 17:06 Triggers, Rules and email Paul <pauljw@truswan.com>
@ 2004-01-20 17:59 ` scott.marlowe <scott.marlowe@ihs.com>
  2004-01-30 15:49   ` Re: Triggers, Rules and email Robby Russell <rrussell@commandprompt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: scott.marlowe @ 2004-01-20 17:59 UTC (permalink / raw)
  To: Paul <pauljw@truswan.com>; +Cc: pgsql-php

On Tue, 20 Jan 2004, Paul wrote:

> Anyone know if I can create a trigger or a rule in Pgsql that will send 
> an email in the event of an attempt to update a database field no-one 
> should be updating?

Sure, that would involve installing the pl language of your choice as an 
untrusted language.  PHP can be installed that way as a pl, btw, then you 
can just use the mail() trigger function in it.

http://www.commandprompt.com/entry.lxp?lxpe=294




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Triggers, Rules and email
  2004-01-20 17:06 Triggers, Rules and email Paul <pauljw@truswan.com>
  2004-01-20 17:59 ` Re: Triggers, Rules and email scott.marlowe <scott.marlowe@ihs.com>
@ 2004-01-30 15:49   ` Robby Russell <rrussell@commandprompt.com>
  2004-01-30 16:00     ` Re: Triggers, Rules and email Aldo Leyva Alvarado <aleyva@medifarma.com.pe>
  0 siblings, 1 reply; 5+ messages in thread

From: Robby Russell @ 2004-01-30 15:49 UTC (permalink / raw)
  To: pgsql-php

scott.marlowe typed this on 01/20/2004 09:59 AM:
> On Tue, 20 Jan 2004, Paul wrote:
> 
> 
>>Anyone know if I can create a trigger or a rule in Pgsql that will send 
>>an email in the event of an attempt to update a database field no-one 
>>should be updating?
> 
> 
> Sure, that would involve installing the pl language of your choice as an 
> untrusted language.  PHP can be installed that way as a pl, btw, then you 
> can just use the mail() trigger function in it.
> 
> http://www.commandprompt.com/entry.lxp?lxpe=294
> 
> 

Yes, plPHP can be used for this. If you want an example, let me know and 
I'll post one on the list.

-Robby

-- 
#-------------------------------------------------------
# Robby Russell,  |  Sr. Administrator / Lead Programmer
# Command Prompt, Inc.   |  http://www.commandprompt.com
# rrussell@commandprompt.com | Telephone: (503) 667.4564
#-------------------------------------------------------



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Triggers, Rules and email
  2004-01-20 17:06 Triggers, Rules and email Paul <pauljw@truswan.com>
  2004-01-20 17:59 ` Re: Triggers, Rules and email scott.marlowe <scott.marlowe@ihs.com>
  2004-01-30 15:49   ` Re: Triggers, Rules and email Robby Russell <rrussell@commandprompt.com>
@ 2004-01-30 16:00     ` Aldo Leyva Alvarado <aleyva@medifarma.com.pe>
  2004-01-30 16:42       ` Re: Triggers, Rules and email Robby Russell <rrussell@commandprompt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Aldo Leyva Alvarado @ 2004-01-30 16:00 UTC (permalink / raw)
  To: Robby Russell <rrussell@commandprompt.com>; pgsql-php

Yes, I want to see an example!!!!!!


Aldo Leyva
----- Original Message ----- 
From: "Robby Russell" <rrussell@commandprompt.com>
To: <pgsql-php@postgresql.org>
Sent: Friday, January 30, 2004 10:49 AM
Subject: Re: [PHP] Triggers, Rules and email


> scott.marlowe typed this on 01/20/2004 09:59 AM:
> > On Tue, 20 Jan 2004, Paul wrote:
> >
> >
> >>Anyone know if I can create a trigger or a rule in Pgsql that will send
> >>an email in the event of an attempt to update a database field no-one
> >>should be updating?
> >
> >
> > Sure, that would involve installing the pl language of your choice as an
> > untrusted language.  PHP can be installed that way as a pl, btw, then
you
> > can just use the mail() trigger function in it.
> >
> > http://www.commandprompt.com/entry.lxp?lxpe=294
> >
> >
>
> Yes, plPHP can be used for this. If you want an example, let me know and
> I'll post one on the list.
>
> -Robby
>
> -- 
> #-------------------------------------------------------
> # Robby Russell,  |  Sr. Administrator / Lead Programmer
> # Command Prompt, Inc.   |  http://www.commandprompt.com
> # rrussell@commandprompt.com | Telephone: (503) 667.4564
> #-------------------------------------------------------
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Triggers, Rules and email
  2004-01-20 17:06 Triggers, Rules and email Paul <pauljw@truswan.com>
  2004-01-20 17:59 ` Re: Triggers, Rules and email scott.marlowe <scott.marlowe@ihs.com>
  2004-01-30 15:49   ` Re: Triggers, Rules and email Robby Russell <rrussell@commandprompt.com>
  2004-01-30 16:00     ` Re: Triggers, Rules and email Aldo Leyva Alvarado <aleyva@medifarma.com.pe>
@ 2004-01-30 16:42       ` Robby Russell <rrussell@commandprompt.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Robby Russell @ 2004-01-30 16:42 UTC (permalink / raw)
  To: pgsql-php; +Cc: Aldo Leyva Alvarado <aleyva@medifarma.com.pe>

Aldo Leyva Alvarado typed this on 01/30/2004 08:00 AM:
> Yes, I want to see an example!!!!!!
> 
> 
> Aldo Leyva
> ----- Original Message ----- 
> From: "Robby Russell" <rrussell@commandprompt.com>
> To: <pgsql-php@postgresql.org>
> Sent: Friday, January 30, 2004 10:49 AM
> Subject: Re: [PHP] Triggers, Rules and email
> 
> 
> 
>>scott.marlowe typed this on 01/20/2004 09:59 AM:
>>
>>>On Tue, 20 Jan 2004, Paul wrote:
>>>
>>>
>>>
>>>>Anyone know if I can create a trigger or a rule in Pgsql that will send
>>>>an email in the event of an attempt to update a database field no-one
>>>>should be updating?
>>>
>>>
>>>Sure, that would involve installing the pl language of your choice as an
>>>untrusted language.  PHP can be installed that way as a pl, btw, then
> 
> you
> 
>>>can just use the mail() trigger function in it.
>>>
>>>http://www.commandprompt.com/entry.lxp?lxpe=294
>>>
>>>
>>
>>Yes, plPHP can be used for this. If you want an example, let me know and
>>I'll post one on the list.
>>
>>-Robby

As requested, here is a simple function that takes 4 arguments ($arg0-3) 
and utilizes the php mail() function. I added the headers for an example 
of how easy it is to utilize plPHP in PostrgreSQL.


CREATE OR REPLACE FUNCTION phpmail(text,text,text,text) RETURNS integer AS '
   # Argument list
   $email_address = $arg0;
   $email_from = $arg1;
   $subject = $arg2;
   $body = $arg3;
 

   #
   # ..Typically, you would validate arguments here
 

   # Build email headers
   $headers  =  "From: $email_from\r\n";
   $headers .= "Reply-To: $email_from\r\n";
   $headers .= "X-Mailer: plPHP";
 

   # Send email
   if (mail($email_address, $subject, $body, $headers)) {
     return 1;
   }
   else {
     return 0;
   }
 

' LANGUAGE 'plphp';


#############################################
# Usage
#############################################
plphp_test=# SELECT phpmail('rrussell@commandprompt.com', 
'webmaster@robbyrussell.com', 'Subject Line', 'This is the email 
body\n\nMore body. Testing email. Test!\n\n\n-Robby') as email;
INFO:  ret_val(long): 1
  email
-------
      1
(1 row)

#############################################
# Output
#############################################
webmaster@robbyrussell.com typed this on 01/30/2004 08:34 AM:
 > This is a body
 >
 > More body. Testing email. Test!
 >
 >
 > -Robby


Feel free to join the plPHP mailing list as well.
   http://mail.commandprompt.com/mailman/listinfo/plphp


Cheers,

Robby Russell



-- 
#-------------------------------------------------------
# Robby Russell,  |  Sr. Administrator / Lead Programmer
# Command Prompt, Inc.   |  http://www.commandprompt.com
# rrussell@commandprompt.com | Telephone: (503) 667.4564
#-------------------------------------------------------



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2004-01-30 16:42 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-20 17:06 Triggers, Rules and email Paul <pauljw@truswan.com>
2004-01-20 17:59 ` scott.marlowe <scott.marlowe@ihs.com>
2004-01-30 15:49   ` Robby Russell <rrussell@commandprompt.com>
2004-01-30 16:00     ` Aldo Leyva Alvarado <aleyva@medifarma.com.pe>
2004-01-30 16:42       ` Robby Russell <rrussell@commandprompt.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox