10 Replies Latest reply on Dec 2, 2008 7:32 AM by David Wu

    how to get custom trigger result when insert

    David Wu Level 1
      I set a trigger before insert, if the result was $aa = 50;
      how to get $aa?

      it doesn't work
      $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", $aa);
        • 1. Re: how to get custom trigger result when insert
          Level 1
          Depends what $aa is? If it is a locally declared variable you need to declare it as a global variable.
          • 2. Re: how to get custom trigger result when insert
            David Wu Level 1
            you mean like this?
            $GLOBALS['aa'] = 50;

            and then what value should I set in insert transaction?
            • 3. Re: how to get custom trigger result when insert
              David Wu Level 1
              This my code, anything wrong? <br /> <br /><?php require_once('Connections/conntest.php'); ?> <br /><?php<br />// Load the common classes<br />require_once('includes/common/KT_common.php');<br /><br />// Load the tNG classes<br />require_once('includes/tng/tNG.inc.php');<br /><br />// Make a transaction dispatcher instance<br />$tNGs = new tNG_dispatcher("");<br /><br />// Make unified connection variable<br />$conn_conntest = new KT_connection($conntest, $database_conntest);<br /><br />//start Trigger_Custom trigger<br />function Trigger_Custom(&$tNG) {<br />$GLOBALS['aa'] = 100;<br />}<br />//end Trigger_Custom trigger<br /><br />// Make an insert transaction instance<br />$ins_testtable = new tNG_insert($conn_conntest);<br />$tNGs->addTransaction($ins_testtable);<br />// Register triggers<br />$ins_testtable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "ins");<br />$ins_testtable->registerTrigger("BEFORE", "Trigger_Custom", 50);<br />// Add columns<br />$ins_testtable->setTable("testtable");<br />$ins_testtable->addColumn("t_name", "STRING_TYPE", "POST", "t_name");<br />$ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "{aa}");<br />$ins_testtable->setPrimaryKey("t_id", "NUMERIC_TYPE");<br /><br />// Execute all the registered transactions<br />$tNGs->executeTransactions();<br /><br />// Get the transaction recordset<br />$rstesttable = $tNGs->getRecordset("testtable");<br />$row_rstesttable = mysql_fetch_assoc($rstesttable);<br />$totalRows_rstesttable = mysql_num_rows($rstesttable);<br />?> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <script src="includes/common/js/base.js" type="text/javascript"></script> <br /> <script src="includes/common/js/utility.js" type="text/javascript"></script> <br /> <script src="includes/skins/style.js" type="text/javascript"></script> <br /> <br /> <br /> <form id="form1" name="form1" method="post" action=""> <br /> <?php<br /> echo $tNGs->getErrorMsg();<br />?> <br /><?php echo $aa;?> <br /> <input type="text" name="t_name" id="t_name" /> <br /> <input type="submit" name="ins" id="ins" value="送出" /> <br /></form> <br /> <br />
              • 4. Re: how to get custom trigger result when insert
                Günter Schenk Level 4
                Hi chan,

                please try with referencing the PHP variable this way:

                $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "".$aa."");

                Cheers,
                Günter Schenk
                Adobe Community Expert, Dreamweaver
                • 5. Re: how to get custom trigger result when insert
                  David Wu Level 1
                  it's not work

                  $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "".$aa."");

                  Error:
                  SQL error: Column 't_num' cannot be null.

                  Developer Details:
                  SQL error: INSERT INTO testtable (t_name, t_num) values ('test', null). (SQL_ERROR)
                  • 6. Re: how to get custom trigger result when insert
                    Günter Schenk Level 4
                    ------
                    it's not work

                    $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "".$aa."");

                    Error:
                    SQL error: Column 't_num' cannot be null
                    ------

                    this means that the variable $aa respectively its value is still not detected -- don´t know why this doesn´t work, but the syntax suggested in my previous post is the correct one however, because this is how you need to embed PHP variables within the "addColumn" context.

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 7. Re: how to get custom trigger result when insert
                      David Wu Level 1
                      but it's not work, are you succeed?

                      code
                      -----------------------------------------------------------------


                      // Load the tNG classes
                      require_once('includes/tng/tNG.inc.php');

                      // Make a transaction dispatcher instance
                      $tNGs = new tNG_dispatcher("");

                      // Make unified connection variable
                      $conn_conntest = new KT_connection($conntest, $database_conntest);

                      //start Trigger_Custom trigger
                      function Trigger_Custom(&$tNG) {
                      $GLOBALS['aa'] = 100;
                      }
                      //end Trigger_Custom trigger

                      // Make an insert transaction instance
                      $ins_testtable = new tNG_insert($conn_conntest);
                      $tNGs->addTransaction($ins_testtable);
                      // Register triggers
                      $ins_testtable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "ins");
                      $ins_testtable->registerTrigger("BEFORE", "Trigger_Custom", 50);
                      // Add columns
                      $ins_testtable->setTable("testtable");
                      $ins_testtable->addColumn("t_name", "STRING_TYPE", "POST", "t_name");
                      $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "".$GLOBALS['aa']."");
                      $ins_testtable->setPrimaryKey("t_id", "NUMERIC_TYPE");

                      // Execute all the registered transactions
                      $tNGs->executeTransactions();

                      // Get the transaction recordset
                      $rstesttable = $tNGs->getRecordset("testtable");
                      $row_rstesttable = mysql_fetch_assoc($rstesttable);
                      $totalRows_rstesttable = mysql_num_rows($rstesttable);
                      ?>

                      result
                      -----------------------------------------------------------------
                      $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "".$aa."");

                      Error:
                      SQL error: Column 't_num' cannot be null
                      • 8. Re: how to get custom trigger result when insert
                        David Wu Level 1
                        I tried this one, actually, {GLOBALS.variable_name} is one of mark-up language,I add echo $a this time, after submit, $a appear on the page, so I think "definea trigger" has been executed successfully, but still got error message <br /> <br />http://uploads.screenshot-program.com/my.php?image=upl2682569831.jpg <br /> <br />code <br />-------------------------------------------------- <br /><?php require_once('Connections/conndb.php'); ?> <br /><?php<br />// Load the common classes<br />require_once('includes/common/KT_common.php');<br /><br />// Load the tNG classes<br />require_once('includes/tng/tNG.inc.php');<br /><br />// Make a transaction dispatcher instance<br />$tNGs = new tNG_dispatcher("");<br /><br />// Make unified connection variable<br />$conn_conndb = new KT_connection($conndb, $database_conndb);<br /><br />//start definea trigger<br />function definea(&$tNG) {<br />global $a;<br />$a = 100;<br />}<br />//end definea trigger<br /><br />// Make an insert transaction instance<br />$ins_testtable = new tNG_insert($conn_conndb);<br />$tNGs->addTransaction($ins_testtable);<br />// Register triggers<br />$ins_testtable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "ins");<br />$ins_testtable->registerTrigger("BEFORE", "definea", 50);<br />// Add columns<br />$ins_testtable->setTable("testtable");<br />$ins_testtable->addColumn("t_name", "STRING_TYPE", "POST", "t_name");<br />$ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "{GLOBALS.a}");<br />$ins_testtable->setPrimaryKey("t_id", "NUMERIC_TYPE");<br /><br />// Execute all the registered transactions<br />$tNGs->executeTransactions();<br /><br />// Get the transaction recordset<br />$rstesttable = $tNGs->getRecordset("testtable");<br />$row_rstesttable = mysql_fetch_assoc($rstesttable);<br />$totalRows_rstesttable = mysql_num_rows($rstesttable);<br />?> <br /> <br /> <br /> <br /> <br /> <br /> <script src="includes/common/js/base.js" type="text/javascript"></script> <br /> <script src="includes/common/js/utility.js" type="text/javascript"></script> <br /> <script src="includes/skins/style.js" type="text/javascript"></script> <br /> <br /> <br /> <br /><?php echo $a; ?> <br /> <form id="form1" name="form1" method="post" action=""> <br /> <label for="t_name">tname</label> <br /> <input type="text" name="t_name" id="t_name" /> <br /> <?php<br /> echo $tNGs->getErrorMsg();<br />?> <br /> <input type="submit" name="ins" id="ins" value="submit" /> <br /></form> <br /> <br />
                        • 9. Re: how to get custom trigger result when insert
                          David Wu Level 1
                          I think it's a bug, because I tried everything that addt offer to define a value for transaction <br /> <br />value from custom trigger <br />session.aa works! <br />cookie.aa works! <br /> <br />value from form <br />post.aa works! <br />get.aa works! <br /> <br />only globals.aa failed, and I am a hundred percent sure it's impossible caused by typing error, because I only substitute the variable when I tried different approaches <br /> <br />//start Trigger_Custom trigger <br />function Trigger_Custom(&amp;$tNG) { <br />$_SESSION['aa'] = 30; <br />} <br /> <br />to <br /> <br />//start Trigger_Custom trigger <br />function Trigger_Custom(&amp;$tNG) { <br />$GLOBALS['aa'] = 30; <br />} <br /> <br />$ins_testtable-&gt;addColumn("t_num", "STRING_TYPE", "VALUE", "{SESSION.aa}"); <br /> <br />to <br /> <br />$ins_testtable-&gt;addColumn("t_num", "STRING_TYPE", "VALUE", "{GLOBALS.aa}"); <br /> <br />and I do one more test, if I define the variable at begin, it's like <br /> <br /><?php<br />$GLOBALS['aa'] = 30;<br />?> <br /> <br />and it works!! <br /> <br />so, I can't pass the value by define variable in custom trigger...
                          • 10. Re: how to get custom trigger result when insert
                            David Wu Level 1
                            Finally I got a solution, although it's not the best

                            function Trigger_Custom(&$tNG) {
                            $aa = 30;
                            $tNG->addColumn("t_num", "NUMERIC_TYPE", "VALUE", $aa);
                            }

                            $ins_testtable = new tNG_insert($conn_conndb);
                            $tNGs->addTransaction($ins_testtable);
                            // Register triggers
                            $ins_testtable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "ins");
                            $ins_testtable->registerTrigger("BEFORE", "Trigger_Custom", 50);
                            // Add columns
                            $ins_testtable->setTable("testtable");
                            $ins_testtable->addColumn("t_name", "STRING_TYPE", "POST", "t_name");
                            $ins_testtable->setPrimaryKey("t_id", "NUMERIC_TYPE");

                            $tNGs->executeTransactions();