5 Replies Latest reply on Jan 15, 2008 1:00 AM by chris.huston.t10

    Simple Database connectivity with Flex?

      Hello all,

      I am new to Flex, and was hoping someone might be able to help point me in the right direction. I have been reading around on how to connect Flex applications to a database backend, but I'm still not clear on how it is normally done. Is this possible using only the standalone free Flex SDK? Or do you have to use additional software (e.g. Flex data services)? Can it be done without using any of the proprietary software?

      Any advice would be very much appreciated.

        • 1. Re: Simple Database connectivity with Flex?
          I think you will need to install flex data services; make a Java project using flex builder; then create an <mx:remoteObject> object which will interact with ordinary Java classes that do all the database connectivity issue.

          • 2. Re: Simple Database connectivity with Flex?
            chris.huston.t10 Level 3
            Flex Data Services is not necessary for connecting to a database. You can use HTTPService calls to PHP or other scripting language such as .net to connect to a database of your choice. You can also use remoting with AMFPHP which is free and quite easy and efficient to work with. I use Flex/PHP/MySql all the time and they work great together.

            • 3. Re: Simple Database connectivity with Flex?
              keith.hughitt Level 1
              Thanks you both for the advice. Do you think you might be able to explain
              what the difference between using HTTPService calls to PHP vs. Remoting with AMFPHP?
              Also, will it ever be possible to handle database connectivity using just the Flex SDK? E.g. something
              like the mysql_connect function for PHP. I'm sure there is a reason why it's not feasible to have something like that right now, but I haven't come across any discussion on the topic. Thanks again for the feedback.

              Take care,
              • 4. Re: Simple Database connectivity with Flex?
                Hi Keith,

                I think the reason Flex doesn't have it's own 'mysql_connect' is that *.SWFs are executed on the clients computer. The DBMS is running on a server - for example at your webhost. Access to the DBMS is most of the time restricted to localhost or certain trusted IPs or domains (security) and furthermore the client running your application would have to have a database-driver installed to communicate with the DB-server.

                As far as I understand, those are (at least some of ?) the reasons why client-side scripting-languages like javascript and flash cannot provide direct connection to DBMS.
                • 5. Re: Simple Database connectivity with Flex?
                  chris.huston.t10 Level 3
                  HTTPService calls send and receive data in String format, often as XML. Remoting uses the AMF3 format which is binary and thus much more compact for large data sets. If you are just transmitting a few records from you DB, then you probably won't notice a difference between the two approaches. In terms of programming, remoting is generally more efficient since you can send value objects and database results directly back to Flex and use the result without having to convert it since AMFPHP takes care of all the serialization for you. This speeds up development for me. However, if you are worried about having to install AMFPHP on the server, then HTTPService is a more generic way to go. AMFPHP is quite easy to setup, though.