best method for connecting to a database though an app

Discussion in 'iOS Programming' started by Dman90, Oct 15, 2011.

  1. Dman90 macrumors newbie

    Joined:
    Jun 25, 2011
    #1
    Hi Everyone,

    as part of a university project, I am designing an app for a web based company.

    Their users login into their website to access promotions and information and they would like them to be able to do the same through the app.

    I have been told the database connections details for the login.

    My question is, what do you think is the best way for me to connect to that database through the app?

    I have just started programming apps btw, so my experience is pretty basic, however i do have a programming background.

    Thanks,

    Dman.
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    It would be ill-advised to expose the database directly to the internet because it makes your database directly attackable.

    Instead build a web services layer on a server that faces the internet. The app uses HTTP to send high-level queries to the web services server, the web services server makes SQL queries to the database (which is now behind a firewall) and then the web services server returns a pre-cooked, high-level response back to the app that the app can easily digest.
     
  3. Dman90 thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #3
    How exactly would you do this?
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    What parts aren't you clear about?
     
  5. Dman90 thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #5
    Sorry If i was not clear before.

    i have been reading up on this and seem to have a solution, at least in theory.

    I will be creating an PHP script that allows me to query the database, and i will be connecting to this PHP page using an API called JSON.

    Correct me if I'm wrong.

    thanks for your helpful advice before.

    D.
     
  6. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #6
    Using JSON has your data exchange format is a good idea. If you're targeting iOS 5.0, there's a new NSJSONSerialization class that can help you out.

    Have you given any thought to what the exchange of HTTP requests and responses will be? Have you considered creating a RESTful web service? If you do, look into the RestKit framework on the iOS side. It also includes a JSON parser for pre-iOS 5. On the PHP side, look at Tonic.
     
  7. Dman90 thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #7
    Thanks for your reply.

    Yes I will be targeting iOS 5 as most people would of probably updated. However if I also wanted to make it accessible for people who have not upgraded, what would I have to change?

    No I have not had a time to reality look into the HTTP exchange yet. I will look into that. Is that what you would recommend as the best option and most secure?

    Thanks,
    Durim.
     

Share This Page