how to connect an iphone application to mysql database

I want to make a iphone application in xcode that has to connect to a remount mysql server. Can't find any good help in this issue. Application may be is of 2 views 1st to show list of contacts sort by date and id's with a image (fields: image, title)in same row. when click goto detail message (image,title and message).
Thing is can't find a way to connect the iphone application to mysql database. any help..??????
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

iOS supports SQLite, not MySQL.  If you decide to work with SQLite, here's a tutorial:
Is it possible to installl Mysql on IPhone? That would suprise me. But anyway if one can install MySQL than the c libraries  should be unproblmatic too. And that is documented in:

But I guess the question is how to connect to Mysql on some Server and for that the above should hold also...
imran-786Author Commented:
As so far i looked, iphone can use only SQLite that comes with iphone. no other database  can be connected. correct me if i am wrong. it seems not right as Android is welcoming all technologies. There are some 3rd party clients available for iphone like Flipper and iMy but i don't think if they can help to wok with iphone app ? Can we import some class to work with it ?
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Do you want to be able to get the database from the Internet or store it in a file in the resources folder of your iOS application?
imran-786Author Commented:
1. we have to link to mysql server , that have database set for this project. So ,yes access type is internet.
2. A web app. will be use to add,edit,update,delete data in database.
3. iSO app. will show data from database. A list of massages title with thumbnails will show on 1st view, when click it will goto next view to show details of clicked 'message title' or 'thumbnail'.

Now problem is do we need to add some client library for mysql as part of app or on iphone to make it connect to server so that is can update list .

codeflux has posted a good example but it is for SQLite that is local database and is limited in nature.

2nd approach i am thinking that if we create the RSS feed url from mySql database then we can use this RSS url to show data in ISo app.

What are the possibilities ..?
Ahh, databasing.  Fun stuff :-)

You have a couple options here.  As you said, XML with an RSS feed would be one option for pulling data from the database.  You can use the NSURLConnection class or the ASIHTTPRequest library to pull and receive information from your database.  With both of these options, you can specify a URL and POST/GET information.  For example, suppose you wanted to use a GET request, your URL may look like this:

Open in new window

Now, you can create the PHP file located at your URL that takes "foo" and "bar" and then uses them to interact with your database... ie:

SELECT * FROM `foo` WHERE `name` = `bar`

Open in new window

Now, you can just get the array of what is returned and then format it in XML or another one of your choice.  

On the iPhone Side, NSURLConnection will return NSData based on the source code and what is returned on the website.  If you returned XML (in an RSS feed, etc.), you can then use the NSXMLParser to make sense of this.  For an RSS tutorial iOS side, check this out:

Now, aside from XML, there is even a more simple way of interacting with your server with NSURLConnection.  If you remember above, NSURLConnection returns NSData based on the source code.  Your PHP script will create an array based on your "mysql_fetch_array" command.  From here, you can use JSON by going json_encode($theArray);

JSON is very easy to use on iPhone and you can use the JSON Library hosted here:  From here, you can use JSON commands with NSString objects.  To retrieve a string from the code, you can use something like:

NSString *string = [[NSString alloc] initWithData:theReturnedData];

Open in new window

So, to sum it up, you can use NSURLConnection or ASITTPRequest to interact with your server.  You will have to develop an API that interacts with your database based on user GET/POST input (this will have to be server side PHP).  From there, you can retrieve the data in XML/JSON and you will be off to the races.

Hope this helps :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imran-786Author Commented:
Thanks SpeedyApocalypse, i will try it and then let you know.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.