i have a Application with a database and i want update the database from net
i used downloading whole database and extract file in database folder but some time get wrong I'd like some advice if there is a better way to do it
You need to create a webservice. This can be done in PHP (I also use RESTful Api's). These services will return JSON which you can parse through.
Try this out:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
Related
I'm making an app in Android Studio that connects to a database and sends a report to it with a POST request with PHP.
What I want to achieve is that when the device doesn't have internet I want the report to save to an internal file and when it detects internet connection it automatically sends it.
My problem is that I use an array with each report and I want an array that contains arrays, and to be sent separately to the database, which I have no idea how to make that. I know how to send a single file every time and with internet, but to save it to an internal file and send them separately and then remove the internal file. I think it would make sense to use a for loop.
If someone could help me, it'd be gladly appreciated.
Your question is about persisting data on device, there are multiple ways to do what you intended.
First & foremost is that you store your local data not in file but in database (SQLITE)
Then you need to form and data structure for sending data. JSON would be best, because is simple to ready and easy
After that, you need a strategy on how to check the internet connection on time interval, for that a Service would do a job, which checks for internet connection on multiple time intervals.
P.S. There are many good and more robust ways to do this, the is what I think is best for your implementation.
I am working on an Android app where the user fills a form and submits it. I want to know which technique to use to store the data. I want to later process this stored data to form reports. Please suggest me the best way to store data and later to produce report.
The form initially will contain one dropbox, date, radio button and edit text.
I found few options below but dont knw how to proceed:
Using JSON
Using Google cloud
I tried code at below link:
http://androidexample.com/How_To_Make_HTTP_POST_Request_To_Server_-_Android_Example/index.php?view=article_discription&aid=64&aaid=89
But dont know how to run the program as it needs serverside php script. I have XAMPP installed on my machine with Apache server running. I can run normal php code but dont know how to make that php code work with my android app.
I am new to server side data handling
Thank you very much in advance. Please help
since you're working with xampp.you can access your localhost from your android emulator using the ip 10.0.2.2/
you will need to use the AsyncTask class and a JSON parser to send your data to your php script.The JSONparser class will remain constant for most of your whole app. You will only have to change the code in your AsyncTask class depending on what data you want to send and the location(php file ie 10.0.2.2/your_file.php or yourdomainname.com/your_file.php) to process the data.
If you don't want to work on server scripting and requires a simple data storage to the cloud then you can try using Parse
Basically Parse provides you with a library that your app can use to pass values to the server Parse is managing.
I am pretty new with this. I am trying to develop some android application in Qt/Qml to query and update data to a database.
The problem I'm trying to solve:
There is a server with a MySQL database. The android application request some data. I use a very very basic php file that query in the database, format an XML and show that file starting with a header('Content-type: text/xml'); sentence, then some echo "<...>" sentences. This php file receives parameters via $_GET array and performs the query.
This is a little archaic but works fine. My client application use Qt/QML for android. It uses XmlListModel to obtain the data from the server and show that data in a ListView.
So far so good, but here is my real problem:
The user of the android application can change some data, and the modified data must be sent back to the server, who performs an update in the database.
My first attempt was to create another php file and send the data in the URI, get it via $_GET and perform the update to the database. This works but there could be many variables and the URI will become very large. I think might be better to send an XML (or JSON) from the client to the server, and put in that file the data for the update.
So, this is the question: How can I send an XML file from Qt/QML to the server? How does the php file obtain that data? Or maybe there is another, better way for doing this.
Every example I find just shows the server-to-client part, or is written in Java, and I don't know java enough.
Additional notes:
After I can solve this I will fight with security: SSL, avoiding SQL injection or anything, but that will be in another question if necessary.
I didn't use SOAP or similar because the first ideas was simple. Also, I have never used SOAP before. If this is the right way, I would be very grateful if you show me how to use it from Qt/QML in android.
Of course, I can use C++ for the client application since it is using Qt.
I use Qt since I already know it and the app might be useful in desktop as well.
Sorry if I made any english mistake.
Thank you in advance.
Ok I found a few questions on how to get data from a MYSql database into an iOS app, but I am just asking a few best practices here. I know these can all be separate questions, but I am hoping that they can be answered in a way that they relate to each other.
Am I correct to understand that to be able to get data into an iOS app - I need to first generate a JSON file, have that stored on a server and than have the app download this file??
If the previous answer is NO then does that mean, I can pull in data on the fly?
Lastly I have seen PHP examples to create JSON files, but iOS is in Objective-c. Does this mean I need to load a UIWebView to be able to load the PHP page that generates the file?
What I have:
I have a MYSql database - it is set up through PHPMyAdmin, so I am not familiar enough with the creation process of the database yet. I will look into that.
I can also export the JSON file from PHPMyAdmin, but that is no good to me in a iOS app.
I also have the parsing from a JSON file into an iOS app sorted, but I want to be able to do this on the fly instead of creating potentially hunderds of files.
I hope someone can help me here:-)
I am not necessarily asking for code, but would be mad to ignore it:-)
The problem is that there are not any iOS libraries for directly connecting to a MySQL server; and you really wouldn't want to do that, anyway. So, you need an intermediary server capable of sending data in a format your iOS application can understand. Note, this does not mean the data has to be JSON formatted. But it is very easy to use JSON as the format for your data. Most languages have native support for generating JSON from its native object format(s).
Once you have a server capable of sending data in your preferred format, you need to write some way for your iOS application to retrieve it. You do not have to use a UIWebView for this. As mentioned, the NSURLConnection framework is very easy to use to make such a request. However, there are a lot of other factors to consider when making network requests and others have already done most of the work for you. I like using the AFNetworking framework in conjunction with JSONKit. AFNetworking makes asynchronous calls to remote web services very easy, and JSONKit is nicer than NSJSONSerialization in my opinion.
What I do to retrieve data from MySQL to my iOS app is:
Create a PHP file on your server and prepare it for GET methods (you're going to send data from the iOS app)
Send a request from your iOS app to your php file, like: "www.yourdomain.com/data.php?name=..."
Process the information on your php file and echo the json output.
When connectionDidFinishLoading: convert the NSData to an Array using NSJSONSerialization.
Do whatever you like with the output information
That's just do way I do. I'm not familiar with other approaches.
PHP (and any other server side language) can take the data from the MySQL database and output it to any client as JSON, on the fly. No need to save the JSON to disk beforehand. Of course, from the client's point of view, there really is no fundamental difference (except the data will always be the latest representation of what's in the database).
You also don't have to use a UIWebView. There's a number of ways to make an HTTP request using Objective-C, but you'll likely want to look at something along the lines of NSURLConnection's sendSynchronousRequest:returningResponse:error: method (I prefer using synch methods inside an async block, but that's not the only way). You can find many tutorials on how to do similar things, as well as higher level libraries to simplify the process.
The app I'm writing needs to get information from a remote database and then store it in the SQlite database on the iphone for offline use. As of now I'm using a php script to query the database and then just basically scrapping the html data from the php echo calls.
My problem is that now that I'm moving away from test data I'm using database tables that are fairly large with complex dependencies. I would really like to not to have to write a parser for these complex files to manually put the data and dependencies into the iphone database.
My question is if there is any way to use a php script to pass to the iphone a copy the actual database file and then just dump that into the SQlite database on the iphone.
While I'm not familiar with iphone development, it seems to me that you ought to be able to just construct the sqlite database file on the server, and then send it to the device (or have the device pull it down). Of course, this is only efficient if you need to send the whole database every time.
If you need to do things more incrementally (you're just adding some new data to the device's database) why not just have PHP write out SQL statements to make any necessary changes, send those to the device, and have the app execute them?
Make the serverss response XML and bring it into core data that way.
http://code.google.com/p/touchcode/wiki/TouchXML will help you parse the response.
You could also make the server send its response in JSON and use this library, http://code.google.com/p/touchcode/wiki/TouchJSON