2

I am new to iOS and am trying to learn how to setup a database remotely and make my project connect to it. I have been searching online for tutorial but can't really seem to find any good ones. So I was wondering if someone could recommend me some good tutorials, to learn how to connect my iOS project to a databases.

Any help is greatly appreciated.

Thanks!

jscs
  • 63,694
  • 13
  • 151
  • 195
FidelCashflo
  • 513
  • 2
  • 10
  • 23
  • possible duplicate of [Wanting a simple overview on how to connect to a SQLite database in Cocoa/Objective-C](http://stackoverflow.com/questions/2830890/wanting-a-simple-overview-on-how-to-connect-to-a-sqlite-database-in-cocoa-object) – matt Apr 10 '13 at 02:04
  • @Viral Well, he did say remotely, but he also tagged his question `sqlite`. So it's hard to guess what he was really after. – matt Apr 10 '13 at 15:40

2 Answers2

0

Ray Wenderlich has some great tutorials for getting Core Data set up locally in your app. Start here. From there, it can be as simple as syncing your database with a cloud service such as StackMob. The exact service you end up using obviously depends on your goal for the project, but both services offer thorough documentation and are a great place to start.

The Kraken
  • 3,158
  • 5
  • 30
  • 67
0

You can start off with connecting a MySQL DB because setting up MySQL is pretty simple. Try this.

This seems like a simliar question. What I would suggest you is that learn basics of PHP, connecting to MySQL via PHP and read all your database contents and echo it as a JSON, your mobile client can use a JSON parser that would parse and give you valid information that was echoed from your PHP script.

For setting up Apache, MySQL , PHP you can go with MAMP for mac or if windows try WAMP server

I have done a small service with MAMP, just echoing a JSON to a client

<?php
// Returns: ["Apple","Banana","Pear"]
echo json_encode(array(fruit1=>"Apple", fruit2=>"Banana", fruit3=>"Pear",fruit4=>"JackFruit",fruit5=>"Guava",fruit6=>"Pomogrenate"));
 ?>

So instead of hardcoded values you should fetch results from your MySQL db and echo it.

<?php
$con=mysqli_connect("localhost or host name","username","password","databasename");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Persons");

while($row = mysqli_fetch_array($result))
{
echo json_encode(array(firstname=>$row['FirstName'],lastname=>$row['LastName']));
echo "<br />";
}

mysqli_close($con);
?>
Community
  • 1
  • 1
Satheesh
  • 10,998
  • 6
  • 50
  • 93