3 Replies Latest reply on Jul 21, 2008 7:50 AM by (shane_mosier)

    Custom Trigger Connection

      Hello All.

      How do I change the connection in a Custom Trigger?

      I want to update a table in a second database.

        • 1. Re: Custom Trigger Connection
          Level 1

          You would do something like this in the custom trigger:

          $query = "UPDATE this_table SET this_field = '1'";

          $update_result = $tNG>connection>execute($query);

          if(!$update_result) {
          $updateError = new tNG_error("Error Updating",array(),array());
          return $updateError;
          } else {
          return NULL;

          This is a basic example that spits out an error if the update is unsuccessful.

          Look at Chapter 16 of the Adobe Dreamweaver Developer Toolbox Help pdf for more information regarding custom triggers. It gives some more examples.

          • 2. Re: Custom Trigger Connection
            Level 1
            Hello Shane.

            I have a insert transaction using Connection_1 and a Custom trigger like your example.

            But I want to update a second Table of a second Databsase using Connection_2.
            Your example is using Connection_1. (The same connection as the Transaction)

            Is it possible to use Connection_2 for the custom trigger?

            • 3. Re: Custom Trigger Connection
              Level 1

              I'm pretty sure you can do this. You should be able to do something like this in the trigger:

              mysql_select_db($database_Connection_2, $Connection_2);
              $query_RecordsetUpdate = "UPDATE....";
              $RecordsetUpdate = mysql_query($query_RecordsetUpdate, $Connection_2) or die(mysql_error());

              This is just the basic code with no error handling, which you may want to add.

              $database_Connection_2 and $Connection_2 need to match the variable names located in your database connection file for Connection_2 located in the Connections folder of your site.

              I have never had to connect to a separate database, but this should work.

              Be sure to add this at the top:


              So that your php script has access to the information for Connection_2.