7 Replies Latest reply on Jul 6, 2006 2:34 PM by Newsgroup_User

    Using two MySQL databases at once

    Level 7
      I have a situation where one PHP page needs to access two MySQL databases
      for different functions (it's in integration thing). I don't think I can
      combine the databases because two different programs are set up and using
      them separately. Is there a way to do this without PHP getting as confused
      as it's getting? Obviously I'm no MySQL and PHP expert.....

      Mad Dog


        • 1. Re: Using two MySQL databases at once
          jeremyluby Level 3
          Yes you can create two separate database connections then use the one for the database you need.
          • 2. Re: Using two MySQL databases at once
            Level 7
            Thanks......do you know of any tutorials or pointers on how to accomplish
            this?

            MD

            jeremyluby wrote:
            > Yes you can create two separate database connections then use the one
            > for the database you need.


            • 3. Re: Using two MySQL databases at once
              Level 7
              Mad Dog wrote:
              > Thanks......do you know of any tutorials or pointers on how to accomplish
              > this?

              If you're using Dreamweaver to create your connections and recordsets,
              you don't need any tutorials. Just create two separate MySQL connections
              in the Database tab of the Application panel. When creating the
              recordsets, make sure you choose the correct connection for each one.
              Dreamweaver generates all the necessary code for you.

              --
              David Powers
              Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
              Author, "Foundation PHP 5 for Flash" (friends of ED)
              http://foundationphp.com/
              • 4. Re: Using two MySQL databases at once
                Level 7
                David Powers wrote:
                > Mad Dog wrote:
                >> Thanks......do you know of any tutorials or pointers on how to
                >> accomplish this?
                >
                > If you're using Dreamweaver to create your connections and recordsets,
                > you don't need any tutorials. Just create two separate MySQL
                > connections in the Database tab of the Application panel. When
                > creating the recordsets, make sure you choose the correct connection
                > for each one. Dreamweaver generates all the necessary code for you.

                That's the problem, both of these are programs that automatically set up
                their own MySQL databases and make the connections (Wordpress and
                EasyPHPCalendar), so it's not so easy to control the connections. Each works
                fine, but if I call the calendar from within Wordpress, it doesn't know to
                switch to another connection and gets all confused.

                MD


                • 5. Re: Using two MySQL databases at once
                  Level 7
                  Mad Dog wrote:
                  > That's the problem, both of these are programs that automatically set up
                  > their own MySQL databases and make the connections (Wordpress and
                  > EasyPHPCalendar), so it's not so easy to control the connections. Each works
                  > fine, but if I call the calendar from within Wordpress, it doesn't know to
                  > switch to another connection and gets all confused.

                  It sounds as though one or both of those applications has been badly set
                  up (although not necessarily by you - it's more likely the way it has
                  been designed).

                  Most programs, including Dreamweaver, use the original MySQL extension
                  within PHP to connect to MySQL. Specifying which connection to use is
                  optional with the original MySQL extension; if no connection is
                  specified, PHP uses whichever was opened last. To use two separate
                  connections, the correct connection must be specified. Dreamweaver does
                  this automatically. You need to look at the PHP code in WordPress and
                  EasyPHPCalender to see if either of them specifies the connection. The
                  easy way to tell is by looking at any line containing mysql_query(). If
                  it contains two arguments, the connection is being properly specified.
                  If it contains just one, that's the program that's causing the problem.

                  --
                  David Powers
                  Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                  Author, "Foundation PHP 5 for Flash" (friends of ED)
                  http://foundationphp.com/
                  • 6. Re: Using two MySQL databases at once
                    Level 7
                    David Powers wrote:
                    > Mad Dog wrote:
                    >> That's the problem, both of these are programs that automatically
                    >> set up their own MySQL databases and make the connections (Wordpress
                    >> and EasyPHPCalendar), so it's not so easy to control the
                    >> connections. Each works fine, but if I call the calendar from within
                    >> Wordpress, it doesn't know to switch to another connection and gets
                    >> all confused.
                    >
                    > It sounds as though one or both of those applications has been badly
                    > set up (although not necessarily by you - it's more likely the way it
                    > has been designed).
                    >
                    > Most programs, including Dreamweaver, use the original MySQL extension
                    > within PHP to connect to MySQL. Specifying which connection to use is
                    > optional with the original MySQL extension; if no connection is
                    > specified, PHP uses whichever was opened last. To use two separate
                    > connections, the correct connection must be specified. Dreamweaver
                    > does this automatically. You need to look at the PHP code in
                    > WordPress and EasyPHPCalender to see if either of them specifies the
                    > connection. The easy way to tell is by looking at any line containing
                    > mysql_query(). If it contains two arguments, the connection is being
                    > properly specified. If it contains just one, that's the program
                    > that's causing the problem.

                    I'm going to have to investigate deeper, but today's not the day for it. I
                    have a zillion other projects I need to get onto but I'll look into it soon
                    and let you know if I have any questions. Hahahaha, boy, will I have some!

                    THANKS!
                    MD


                    • 7. Re: Using two MySQL databases at once
                      Level 7
                      David Powers wrote:
                      > Mad Dog wrote:
                      >> That's the problem, both of these are programs that automatically
                      >> set up their own MySQL databases and make the connections (Wordpress
                      >> and EasyPHPCalendar), so it's not so easy to control the
                      >> connections. Each works fine, but if I call the calendar from within
                      >> Wordpress, it doesn't know to switch to another connection and gets
                      >> all confused.
                      >
                      > It sounds as though one or both of those applications has been badly
                      > set up (although not necessarily by you - it's more likely the way it
                      > has been designed).
                      >
                      > Most programs, including Dreamweaver, use the original MySQL extension
                      > within PHP to connect to MySQL. Specifying which connection to use is
                      > optional with the original MySQL extension; if no connection is
                      > specified, PHP uses whichever was opened last. To use two separate
                      > connections, the correct connection must be specified. Dreamweaver
                      > does this automatically. You need to look at the PHP code in
                      > WordPress and EasyPHPCalender to see if either of them specifies the
                      > connection. The easy way to tell is by looking at any line containing
                      > mysql_query(). If it contains two arguments, the connection is being
                      > properly specified. If it contains just one, that's the program
                      > that's causing the problem.

                      I think I've got it. There might be other tweaks needed, but I moved the
                      EasyPHPCalendar table into the same database as the Wordpress table. With
                      luck (I'll know tomorrow when I mess with it) that should cut the confusion
                      factor!

                      Thanks,
                      MD