Problem to accessing Mysql remote database - iphone

First m very sorry!! for that i m asking question again related to accessing data from server.
i am new in iphone and am making a application in which require to access mysql database which is hosted on remote server,
I take a server and create our database on the server
so i have URL of the server,User Name,Password,Port Number.
I make a servlet for accessing data from the server database and generate the xml file.
I make my application and with the use of xml parser i use the data in my application.
but problem is this,
where i put my servlet which give xml file when required in my application,
On the Server?
In the Application?
i m confuse how i use servlet in my application.
If u have any reference or source code then please suggest.
Thanks,
Arun

It probably would be better to put it in the application so that your reducing the need to call the server for the details.

Related

How to get data from MySQL generated XML?

I have an app to send data from iPhone to MySQL server and I got it with request from objective-c and php on server.
Now, I want to receive data from server by XML. I have created a php code to generate data from MySQL to XML. How can I code in objective-c to call this php code? The goal is using this XML to parse and display on iPhone (I have objective-c code to parse xml file from link on server).
Please help me if you know and used to work on that.
Use Web-servces Like XML- RPC, SOAP ,REST
To connect to a mysql database, your best bet is to use JSON/SOAP/XML/PHP or some combo of the mentioned, to talk between your database and your app..
The reason database connection directly from the device is a bad idea, is that you have to enable global external access to it for it to work. You can keep your data safer by having scripts on your server do the communication to the database.
Your server needs to expose a service of some kind (a URL the iPhone app can call).
Your app can call this URL with NSURLConnection (or lots of others).
This will return you an NSData * object.
Your app will then need to parse this raw data into XML (or JSON or a few others). You can use NSXMLParser (and lots of others) to do the parsing.
Then, you need to translate the XML into useful business objects.

how to send database data to a MySQL server to update the server database

I am developing Smoking counter and I need to send all the smoking record (about the time user smoking) to database on the server. The server database is MySQL database. I knew that I must have send data to PHP page/script, and this page/script will run on the data to insert record to database.
I would like to know: is there another way to update database, because I don't have knowledge about PHP. I used to work on java and c/c++/objective-c. If you know another way to do this task, please let me know.
Any help would be appreciated.
If you already know Java, C and C++, then you should be able to learn how to write your php script really quickly, just google a tutorial.
While could run a Java server using a servlet to insert the data, PHP is far easier to deploy, and you should only need to write a few lines of code.
I you do use PHP though one thing to remember when inserting to your database is to run all your parameters to add through mysql_real_escape_string
Edit:
To give an example, this script when configured would insert a name and location to a database:
<?php
$link = mysql_connect("hostname", "username", "password");
mysql_select_db("databasename");
$location = mysql_real_escape_string($_POST['location']);
$person = mysql_real_escape_string($_POST['person']);
mysql_query("INSERT INTO mytable(location, person) VALUES('{$location}', '{$person}')");
mysql_close($link);
?>
You may use any server side solution you like which has a MySQL interaction class library, e.g. Java servlet or C/C++ CGI application. You will also need a web server (e.g. Apache or Apache Tomcat) which will take care of HTTP requests.
PHP is not the only way to write programs which use MySQL.
You can you this API hosted on github.com .
https://github.com/gwdp/Obj-c-MySql
It's free and very well documented .

Client Server Applications for Iphone

I have a question regarding this topic.Like for Client Server Applications
1) is it necessary to load database directly into the Application.
Suppose if I have a DB in the back end and My application has to connect to that DB and display the results on the View for this do I need to Add DB into the Application directly.
2) can we access any DB or a File on the Remote server and show the required results.( with out adding that particular DB or A File into the application directly). How can we do this.
I saw a similar question in stackoverflow one answer was to use a PList, I am new to this.I am browsing the net but not able to get clear results. I lost many of my interviews because of this question.
Thanks,
1) is it necessary to load database
directly into the Application.
Suppose if I have a DB in the back end
and My application has to connect to
that DB and display the results on the
View for this do I need to Add DB into
the Application directly.
I'm not sure I understand this question. No, you don't need to load a database directly into a client in a client-server architecture. Normally, when I think of a design where a server has a database, I imagine there's some kind of way for the client to query the server for information. Perhaps it's making HTTP requests, which the server parses into a query, runs the query, and then returns the results (perhaps in XML form?).
2) can we access any DB or a File on
the Remote server and show the
required results.( with out adding
that particular DB or A File into the
application directly). How can we do
this.
Are you asking if it's possible, in general, to access a server database from a client? Yes, of course. (See above, re: HTTP Requests).
Any arbitrary file? That depends on how the server is set up. Again, HTTP is one protocol works that way; if you send an HTTP query like "GET someimage.png HTTP/1.0", the server could just be grabbing the whole file someimage.png and sending it back in the response. (Technically, it's not necessarily snarfing a whole file -- it could be creating that PNG dynamically since there's nothing in the HTTP protocol that says it must be sending an existing file -- but that's outside the scope of your question.)
I lost many of my interviews because
of this question.
Not to sound too snarky, but interviews are often won and lost not because you don't know the answer, but when you can't communicate effectively. You haven't phrased your question(s) here particularly well.

Is it possible to connect to SQL server in iPhone?

Is it possible to connect to SQL server in iPhone?. I want to create a new application and i want to retrieve the data from SQL Server and displayed. Previously it created using ASP.NET and SQL Server. Now my client wants to display the datas which is retrieved in SQL server data base. But the database contains the huge amount of data. So is it possible to convert the SQL Server to SQLite.(But SQLite is a light weight components). How can i do that? Can i use Web services? or i will ask to server side and convert the XML file and then i will use XML Parsing. I have no idea about it?
Please Explain Me!
Thanks.
i don't work on an iPhone app but i know that our guys that do use webservices that return pure xml with data, return that to the iphone and then parse that xml.
Wow... You are actually wondering if you can connect your iPhone-application to a SQL-server directly? Are you insane?! If you do, you need to connect with host-, username-, password-, en db-name-parameters. When people 'hack your binary converting it back to the source-code (.m-files)' they can read these parameters and create a custom connection to your db-server.
So, what you need to do is create a few scripts that parse your DB-data and return it as xml-data, so hackers won't be able to loggin into your db-server.

How to synch SQLite data to server in iPhone

I'm a total noob when it comes to iPhone development and have been tasked to create a database app that can download and upload sqlite data to and from a server via http using web services. So far I already have a form for retrieving and saving data to a SQLite database and now I need some information on how I can upload the SQLite data to a server. The SQLite database will only have one table with 3 columns and about 200 rows max. I hope somebody can point me to the right direction or lead me to some sample codes.
Appreciate any help.
As you are using HTTP to get data into the iPhone, you should also use HTTP to get data out of the iPhone. That way, you can query the SQLITE database and send the data through HTTP to a remote server.
It's pretty simple to accomplish since you have all the HTTP protocol implemented in the SDK.
On the server side, you can use whatever you want: Apache+PHP, Tomcat, JBoss, ASP.NET, you name it.