Subject Re: [firebird-support] Using events with php
Author
Ok - that last php test function was a combination of different attempts
- with several obvious errors. Something that actually almost works
follows - it almost works in that it does exactly what I want it to by
spewing the newly added events - but I'm only receiving the "ALLRAW"
event. The per node event that I THOUGHT I was creating in the firebird
trigger of "RAW:1234" appears not to be generated. Where am I wrong?

<?php
error_reporting(E_ALL);
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
session_start();
$iplink_node = 1116;
$dbh = ibase_connect( 'test.fdb', 'SYSDBA', 'masterkey', 'ASCII' );
$evs = "RAW:$iplink_node";

while ( $handler = ibase_wait_event( $dbh, "ALLRAW", $evs ) ) {
// just keep looping...just keep looping...
echo "$handler\n";
$handler = "RAW:1116";
raw_line_handler( $handler, $dbh );
flush();
}

function raw_line_handler( $event_name, $dbh ) {
$iplink_node = substr( $event_name, 4, 4 );

echo "iplink is $iplink_node\n";

$qs = "select first 1 RAWLINE from RAW_IPLINK where IPLINK=? order
by RECEIVED desc";

$th = ibase_trans( $dbh, IBASE_READ );
$qh = ibase_query( $th, $qs, $iplink_node );

if ( $qh ) {
while ( $row = ibase_fetch_row( $qh ) ) {
echo $row[0] . "\n";
}
ibase_free_result( $qh );
}
ibase_commit( $th );

return true;
}

?>



---
Daniel

On 2015-08-25 14:43, dmiller@... [firebird-support] wrote:
> I have the following trigger:
>
> CREATE TRIGGER TRIG_RAW_IPLINK_EVENT FOR RAW_IPLINK ACTIVE
> AFTER INSERT OR UPDATE POSITION 1
> AS
> DECLARE VARIABLE iplink char(4);
> DECLARE VARIABLE received varchar(40);
> DECLARE VARIABLE eventstring varchar(44);
> BEGIN
> iplink = cast(new.IPLINK as char(4));
>
> eventstring = 'RAW:' || iplink;
> post_event eventstring;
> END^
>
> So, what I THINK happens - is on any insert or update (and on this
> table
> it's only inserts) I should be generating events named RAW:1116, or
> whatever iplink happens to be. new.iplink is a smallint that is always
> 4 digits.
>
> Assuming I've got that part right - over in php land I have the
> following. Obviously I'm doing something wrong - I just have no clue
> what yet. The output of the below gives me my two sanity checks - but
> nothing from the loop.
>
> $iplink_node = 1116;
> $dbh = ibase_connect( 'test.fdb', 'SYSDBA', 'masterkey', 'ASCII' );
>
> echo "Database handler $dbh\n";
>
> $evs = "RAW:$iplink_node";
> echo "Event is $evs\n";
>
> while ( $handler = ibase_wait_event( $dbh, "raw_line_handler" ) ) {
> // just keep looping...just keep looping...
> echo "$handler looped\n";
> flush();
> sleep(1);
> }
>
> function raw_line_handler( $event_name, $dbh ) {
> $iplink_node = substr( $event_name, 4, 4 );
>
> echo "iplink is $iplink_node\n";
>
> $qs = "select first RAWLINE from RAW_IPLINK where IPLINK=? order
> by
> RECEIVED desc";
>
> $qh = ibase_query( $dbh, $qs, $iplink_node );
>
> if ( $qh ) {
> while ( $row = ibase_fetch_row( $qh ) ) {
> echo $row[0];
> }
> }
> return true;
> }
>
> --
> Daniel
>
>
>
>
> ------------------------------------
> Posted by: dmiller@...
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Documentation item
> on the main (top) menu. Try FAQ and other links from the left-side
> menu there.
>
> Also search the knowledgebases at
> http://www.ibphoenix.com/resources/documents/
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ------------------------------------
>
> Yahoo Groups Links
>
>
>