How to access sql server from Android the clean way? - php

On my project, I'm using a php site for getting data from sql server.
My android app connect the php site and send values , php site take values with POST method, and get the intended values from sql, after that, write in a html div(has an id), and last my app get data from html div with jsoup parser.
This way is working correctly, I'll ask about performance, when I Googled I saw a library called jdbc, so if I connect my app directly to sql server, is it get less loading time, or my way is true?
Sorry for my bad English :(

when I Googled I saw a library called jdbc, so if I connect my app directly to sql server
You can connect your app to sql server as long as sql server is accessible from Internet or your app has access to a network where sql server is accessible.
is it get less loading time
You can expect far better response time because you won't need the php site anymore as long as your JDBC code is well written.

Related

SQLite persisting data via php to MySQL server iOS

Sorry in advance for sounding like a novice but I'm very new to app development and hope someone can help me!
I'm trying to create an iOS app that will store data locally when offline (i.e. an email address) and once connectivity to the internet is available will persist that data across to a server.
First I created an SQLite database which I done using the db browser tool, and everything for the most part is working the way it should. The app uses Core Data to persist to a SQLite DB.
Next I created a php file that would check for an internet connection then select the SQLite db and it's data then insert that data into a MySQL db.
This is where I got stuck. Am I right in thinking that the data saved in the SQLite db when running on a device is saved in the device's document directory?
If this is true then how do I gain access to it via the php file for it to be persisted over to MySQL server?
Am I missing something? What is the correct way of persisting this data across from the SQLite db on the device to my MySQL server?
Many thanks in advance for any help.
It sounds like you want to store your data in a cookie (the email address), and post to the server when online. You would not need a offline client DB for data as small as an email address.
You could do this with AJAX (Asynchronous Javascript), posting to an awaiting php file based upon a Javascript file.
PHP communicates to MySQL very well with a LAMP/WAMP (Linux/Windows-Apache-MySQL-PHP) type server (or Ios version: IAMP?). With AJAX, you would $_GET or $_POST to the PHP file, and then write the data (after sanitizing) to the MySQL database with either MYSQLI or PDO, preferably with a prepared statement.
To get the data back from the server, you would have another PHP file that could be loaded (again by AJAX) to query MySQL with a simple SELECT statement.
I am suggesting AJAX here because it would not require user interaction to post; you could set a timer to continually check for an internet connection, and post when it does come online. You could also have a similar timer to sync with the server database. Keep in mind, a timer based AJAX will put a constant load on your server, so this may not be too scalable.

Can I run PHP Scripts on iOS device?

I have an application that gets data from a SQL Server database using a PHP Script stored in an online server.
I get the data on my iOS app with NSURLConnection, I connect to the script and the script executes the queries on the server.
My question is, can I store this script on the iPhone or iPad and forget the online server?
Also, can I execute SQL Server queries without PHP Scripts and POST methods?
If your database is static(no update), then you can use iOS's native CoreData to manage the database locally and you dont need internet connection at all.
If your database needs to be updated after you release your application, then you will need a server.
In either case the programming language on iOS will be Objective C and C++ (instead of Python).
I was searching a lot of time for some library to do that I want. I found this library:
https://github.com/martinrybak/SQLClient
Main blog of the proyect:
http://objcsharp.wordpress.com/2013/10/15/an-open-source-sql-server-library-for-ios/
If you know another Libraries you can post in this thread for help the people with the same problem.
Regards.

Results from PHP doesn't change

I'm currently developing an application in flash that requires me to save data into a remote MySQL database. I use a PHP page to send and receive data from the database and it works fine. However, new updates from the database are not fetched by the PHP page requested by my flash app, even if I reload it. It's like receiving the same old data over and over again. What could possibly wrong with my processes? Can there be a simpler way to access a MySQL through Actionscript without the use of PHP? Thanks!
Check the query in the php page (attach it)
Emulate the request without using Flash - use your browser or a network debug proxy like Charles and see what you get
Are you using Zend_Amf ?
Using flash to directly access a database is something unusual (to me at the very least). It would require authenticating the Flash application against the database server, sending queries up to it and developing a way of parsing the results. It doesn't make things any simpler and adds a great deal of concerns.

Python sync with mySQL for local application?

There have been many questions along these lines but I'm struggling to apply them to my scenario. Any help would be be greatly appreciated!
We currently have a functioning mySQL database hosted on a website, data is entered from a website and via PHP it is put into the database.
At the same time we want to now create a python application that works offline. It should carry out all the same functions as the web version and run totally locally, this means it needs a copy of the entire database to run locally and when changes are made to such local database they are synced next time there is an internet connection available.
First off I have no idea what the best method would be to run such a database offline. I was considering just setting up a localhost, however this needs to be distributable to many machines. Hence setting up a localhost via an installer of some sort may be impractical no?
Secondly synchronization? Not a clue on how to go about this!
Any help would be very very very appreciated.
Thank you!
For binding Python to MySql you could use HTSQL:
http://htsql.org
You can then also query your MySQL DB via http requests, either from AJAX calls or server-side e.g. cURL (and of course still have the option of writing standard SQL queries).
There is a JQuery plugin called HTRAF that handles the client side AJAX calls to the HTSQL server.
The HTSQL server runs on localhost as well.
What OS would you be using?
How high-performance does your local application need to be? Also, how reliable is the locally available internet connection? If you don't need extremely high performance, why not just leave the data in the remote MySQL server?
If you're sure you need access to local data I'd look at MySQL's built-in replication for synchronization. It's really simple to setup/use and you could use it to maintain a local read-only copy of the remote database for quick data access. You'd simply build into your application the ability to perform write queries on the remote server and do read queries against the local DB. The lag time between the two servers is generally very low ... like on the order of milliseconds ... but you do still have to contend with network congestion preventing a local slave database from being perfectly in-sync with the master instantaneously.
As for the python side of things, google mysql-python because you'll need a python mysql binding to work with a MySQL database. Finally, I'd highly recommend SQLalchemy as an ORM with python because it'll make your life a heck of a lot easier.
I would say an ideal solution, however, would be to set up a remote REST API web service and use that in place of directly accessing the database. Of course, you may not have the in-house capabilities, the time or the inclination to do that ... which is also okay :)
Are you planning to run mysql on your local python offline apps ? I would suggest something like sqlite. As for keeping things in sync, it also depends on the type of data that needs to be synchronized. One question that needs to be answered:
Are the data generated by these python apps something that is opague ? If yes (i.e. it doesn't have any relations to other entities), then you can queue the data locally and push it up to the centrally hosted website.

Android connection to MySQL - Php or Servlet?

This is not a codefix question but please help me where possible.
I am developing an application which needs to store information in a database. This information needs to be stored off-device for security reasons (patient data).
I have explored using PHP as a bridge to the external MySQL database hosted locally via WAMP, however I have recently been informed of servlets and also of SQLite.
As I am learning these technologies under a limited time frame I need to know which to invest my time into to get the job done as easily as possible. I have no experience with any query language but I did get a simple login screen to work on Android using PHP and MySQL on WAMP using HTTP post/fetch within android.
Also, is it possible to store the information in SQLite within android and write that data to a server, which can then load the SQLite database again on re-launch?
Many thanks for your time!
From our expericence these kind of services need to work offline if possible. Both 3g and especially wifi has been unreliable in several occasions.
You do good if you save the data locally in e.g. sqlite database but be warned the data can get wiped on OS update or software update.
Also try to write your changes/additions in batches and servr updater can send all the batches that are not yet on the server. this way it's more reliable if you miss updates.
These kind of interfaces to another systems take a lot of time in testing. Consider getting a new timeframe in advance.
You will find more about Android connection to MySQL here

Categories