Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Trigger use

phpMyEdit General     Trigger use
Odoslať novú tému   Odpovedať na tému    
 
tonymcc     Založený: 15.01.2009   Príspevky: 6  
Príspevok Zaslal: 2009-01-15 07:31
Návrat hore  Odpovedať s citátom     

I am using version 5.7.1 right now. (I just purchased MFG but haven't gotten it yet). However, I having difficulty getting a trigger to execute at all.

The examples don't actually have much detail on how to use the triggers or enable them.

The code looks like this right now:

Kód:

<snip>
$opts['triggers']['update']['after'] = 'updatelastid.TAA.inc';

// Now important call to phpMyEdit
require_once 'phpMyEdit.class.php';
new phpMyEdit($opts);
<snip>


It does not ever run. What am I doing wrong? Everything else I've done so far is working great.


For test purposes the trigger code itself looks like this:
Kód:
<?php
    print '<br/> TRIGGER CODE EXECUTED <br/>';
    return(true);
?>


By the way.. I realize that triggers are for invisible actions, but I was not having any luck, so, just as a test I put the print call in.

What I really want to do is update a separate table with the value of the an assigned ID # + 1, I use the table lookup to get the next number and on save in Add Mode only I will increment that number. For technical reasons it has to be a sequence table not an integrated AUTO_INCREMENT field.

 
tonymcc     Založený: 15.01.2009   Príspevky: 6  
Príspevok Zaslal: 2009-01-15 10:17
Návrat hore  Odpovedať s citátom     

I have managed to get the call to work as a 'php' field option, which proves to me that at least the script will run and update the table I want. However treating it like a trigger does not.

Using a direct 'php' action measn I would have to write all the pre/post/cancel logic. I'd much prefer the trigger to work.

You can see below that I am using a values table lookup in 'ADD' mode to get the next ID number, so I just need to increment it on successful save for specific type of 'parrent' record.

Kód:
$opts['fdd']['PrimaryID'] = array(
  'name'     => 'Primary Member ID',
  'select'   => 'T',
  'maxlen'   => 10,
  'sort'     => true,
  'values|A' => array(
     'table'       => 'coopids',
     'column'      => 'NextID',
     'filters'     => 'IDName = "PRIMARY" '),  //lookup the last ID in ADD mode
  'php'      =>'updatelastid.php'
);


Any help you may have would be appreciated.

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2009-01-15 21:41
Návrat hore  Odpovedať s citátom     

If you want the trigger to grab the ID of the last record added (in Add mode) then you need ['insert']['after'] instead of ['update']['after']

Posting the complete trigger would be helpful in understanding the goal.

 
tonymcc     Založený: 15.01.2009   Príspevky: 6  
Príspevok Zaslal: 2009-01-15 21:59
Návrat hore  Odpovedať s citátom     

At this point the trigger won;t execute not matter what I put in it, But here's the code I used fpr the 'php' field option call
Kód:
<?php
// TRIGGER TO UPDATE LAST ID

    $this->myquery("UPDATE `coopids` SET `LastID` = `LastID` +1 WHERE `IDName` = 'PRIMARY'");
    return(false);
?>


As you can see I don't need to know the internal record ID of the current record, I just need to increment a field in a separate table AFTER as succesful save in the main table.
I do need to be able, eventually, to check that the value of a field called 'Relationship' is equal to 'P' as a pre-req to incrementing the LastID field.

This spinnet is incomplete as I am trying to just prove that it will execute as a trigger at all right now and it does not.
--Tony

doug Napísal:
If you want the trigger to grab the ID of the last record added (in Add mode) then you need ['insert']['after'] instead of ['update']['after']

Posting the complete trigger would be helpful in understanding the goal.


 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2009-01-15 22:20
Návrat hore  Odpovedať s citátom     

Build in some error checking?

Kód:
if($this->myquery("UPDATE `coopids` SET `LastID` = `LastID` +1 WHERE `IDName` = 'PRIMARY'")){

   return true;

}else{

   echo "\n".'<p>'.mysql_error().'</p>';

   echo "\n".'<a href="javascript:history.go(-1)" onmouseover="self.status=document.referrer;return true">Go Back</a>';

   @mysql_close($this->dbh);

   require_once('./inc/footer.php');

   exit;

}


 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2009-01-15 22:21
Návrat hore  Odpovedať s citátom     

Variables available within a trigger include:
$this - object reference
$this->dbh - nitialized MySQL database handle
$this->key - primary key name
$this->key_type - primary key type
$this->key_delim - primary key deliminator
$this->rec - primary key value (update and delete only)
$newvals - associative array of new values (update and insert only)
$oldvals - associative array of old values (update and delete only)
$changed - array of keys with changed values

 
tonymcc     Založený: 15.01.2009   Príspevky: 6  
Príspevok Zaslal: 2009-01-15 22:24
Návrat hore  Odpovedať s citátom     

Well, I'll be. Changing it to [insert][after] and this minor tweak below (thanks to the mfg txt examples) seems to have done the job!

Kód:
<?php
// TRIGGER TO UPDATE LAST ID

    if($newvals['Relationship'] == 'P') {
        $this->myquery("UPDATE `coopids` SET `LastID` = `LastID` +1 WHERE `IDName` = 'PRIMARY'");
        return(false);
    }
   
?>


NOW I'll add the error checking ... I try and keep it simple to start with, thanks for the help.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov