Web Service in Python - php

I installed rapidsms in local for send messages. The application tested with local server. Now i would like to store the incoming messages in another database via a php application. Means when a message received in rapidsms (Django-Python) app, i want to call a php application function and store message in php app database. For this which method is best?
Thanks

You could use python-suds to communicate via WSDL with your PHP app.
IMHO the best option would be to inspect the PHP database and directly store the data from python. Low latency and no overhead.

Related

Build webservice for both website and app

I've developed an android app that interact with my database by using some php scripts (one for each function of my app) that returns a json object with response data.
Now i need to build up a website too that do the same tasks of my app, but i would fix up my server code.
Should i have to maintain my app php scripts separate from website scripts (i'm planning to use some php framework to develop it), or there's a different way to do it?
No! Same script will work for all platforms.
If you follow proper protocols you will be good :)
Use Rest Console or similar tools to test your webservice on browser.
If you are able to get JSON response, then its good for all platform.
If you want to separate out the platforms and devices on server that can be handled by using user agent check at server end.

Does an android app follow client side/server side architechture with regards to database?

I am an android newbie who is coming from PHP background. In PHP basically what happens is that
all of the database connections happen in php code(server side) and then it later coverts in html code(client side).
From what I have seen in android for database connection, we write a service in php using mysql. And from our Android java class, we make the service call(always aysnc I think), and then when the result comes, we update the UI(kinda like Ajax architecture and gwt).
The system above makes sense to me. I read somewhere that even though using JDBC is not practical on android, it can be still be used. Let' say for example's sake, we want to make the database call through JDBC. In a normal web app, I would put it in a servelet. But in android, we don't have that. All we have is UI widgets code.
So just to the understand the architecture, could someone please explain to me where I would make the JDBC call in the code? or in broader terms does it's architecture differ from traditional client/server side?
Like Php:
A brief recap of what you used to do in PHP is as follows:
Connects to MySQL server using PHP
Query the server using PHP function
MySQL server receives, parse the query and send the results back
PHP parses the response and then you displays (or do anything with) it
PHP has built in support for MySQL library.
Now in android we have built in support for SQLite. But the difference is SQLite stores its data on the device itself not on the server.
For database operations same procedure is followed using SQLite:
Using Android(Java) activity it connects to SQLite database
A query is sent to database
SQLite engine receives, parses the query and sends the results back
Android activity receives the result and then you can do whatever you want with it
But, Here comes the issue
This is only good if you want to store the data locally, like saving a users score.
Suppose, you want to have a leader-board in a game you built. Then you can't do it this way, because data is stored locally on all devices. For this we need to have all the users data stored on one/same place.
The Solution (like~in PHP)
We will save our data on an online server and will retrieve it whenever required. We can connect to any database engine on the server but MySQL is fast as compared to others. So, we will use MySQL as our database server and connect to it using a PHP web service.
That web service will do all (mostly CREATE and READ) database operations for you. This way you can save the data in the server and retrieve it globally whenever you want.
But, how it is done? Here are the steps:
Create a web service
A collection of PHP scripts which can read and write, to and from database
For security, plug in something like OAuth to perform transactions and encrypt data being transferred (Best will be to write this type of service in a framework)
Send READ or WRITE request from Android activity to web service
Web service receives, authorize, parse the request
Web service then sends the appropriate request to MySQL server
MySQL server receive, parse the query and send the results back to web service
Web service receive, parse the response and send the results back to Android activity
Android Activity receives the data and then you can play with it :)
You might have private databases in Android itself without using JSON etc. Just like you used in PHP with MySQL.
You might find lots of tutorials about SQLLite. But, here is official documentation of Google's Android page: http://developer.android.com/reference/android/database/sqlite/package-summary.html
The short answer is you can't use JDBC in android. The reason is JDBC is too heavy for mobile.
But you can use built in SqLite support to work with your local sqlite database. It has some limitations comparing to JDBC MySql driver but it should fit your needs.
Usage of SqLite is simple:
Connect to database
Send query
Get your data
Process data
The only thing you have to remember is that you should not use SqLite in main thread. You may create your own with Thread but the simplest solution is to use AsyncThread.
If you want to make calls to remote MySql database then your way is a bit more complicated
Write server side code that will handle requests from android and send it to database(e.g. using JSON)
Send request to remote server from your android device
Receive server's answer
Process it
As in above method with SqLite you should do it in a background thread to not to block UI.
-If needed you can use a local database (using SQLite)
-Server/client side in android are similar to any other application: you need a WebService handler which is usually (best practice) an AsyncTask.
Solution: nice and easy...
Create a .php that does the job for you, parse the result as a json workflow. Use your asynctask to get and parse the result. Add data to your database if needed. You can finally display a nice UI in the onPostExecute method.

Write data back to my backend server from a packaged Sencha-Touch 2 App

I am trying to write a Sencha Touch application that I can package in PhoneGap for iOS, Android etc...
The app allows you to input some data which I would like to save to my backend server using PHP/MySQL. It all works when I use an AJAX proxy as I am testing the app on the same server as my database.
However when I package it for mobile devices I run into the same-domain restrictions of AJAX calls. So I modified it to use the JSONP proxy and I can read the data from the server database but have no idea how to write records back. Do I need to somehow pass the data in the GET request? Obviously the server side PHP needs to be different because of the callbacks and the fact JSONP is forced to used GET requests. I am also trying to get CORS working but currently no success.
So my question is how would I implement writing data back to my backend server from a packaged mobile Sencha app running on a mobile device? Either using JSONP if that is even possible or any other alternatives are welcome?
Many Thanks…

Connecting MySql with Android without using PHP

I want to connect a MySql DB with my android application.
However, I DON'T want to/CAN'T use PHP for doing this.
Almost all solution for MySql connection with android on internet uses PHP.
I read somewhere that, If one don't want to use PHP then web service should be used.
But I'm not able to find any tutorial/sample example for the same.
Any help appreciated.
It seems you're mixing up some things.
A web service is simply some code on the internet (web) which allows you to receive and send information to a server, where it is saved per example in a database.
PHP is just a language, in which you can write a web service.
You can use a vast array of languages to create a web service ( read: expose your database) to other devices. Among others, you can easily do this in Java, .NET, Python ...
If you're looking for a way to connect to an external database without any web service / API in between, i'll have to disappoint you with the news that this is not supported by Android.
Most examples of a simple web service / a bunch of scripts contain PHP since this is probably the easiest and can be used on pretty much any server.
A webservice, is as it's called, a service, meaning that you have one side consuming it (the android client). if all you want is a persistent storage, you could use SQLite which is an SQL compliant solution which exists within android.
If it's possible to SSH to a server via Android, you could use that to connect to mysql, because the only other solution involves having mysql binaries installed locally on your android machine, and that's not possible AS FAR AS I KNOW, on Android.
One major reason for using a webservice (e.g. written in PHP) to connect to a remote DB is that you don't want to store the database login credentials inside your app. Because otherwise it'll be easy to extract your login for that database and access and edit it in a way you might not have planned (eg. delete stuff).
Its Possible to connect mysql database .
I have done with out using php file . I have used an spring configuration file to establish an connection to the database and dao to access the data from the database.
Create an Web Application that access the Server through the Spring Framework and an Servlet .
Create an Android Client Application tat make an get / post request to the Servlet , process the results in the servlet and return the response to the Android Client Application (json format ) Process the json format reponse in the Android Client Side and use it to your application

Transferring data from one server to another in php

I want to transfer 10 user details from my server database to another server.The other server can call a php page (in my sever) which can supply the needed 10 user details.This should happen in such a way that a user using the site must not understand that the data is coming from another server.
I will recommend using WebService for this purpose. In the Server A (provider) you will code this webservice to serve the users as requested by server B(consumer), So you will be able to consume the services provided by A at any time and being transparent for the USER.
References:
WebService
XML-RPC
SOAP
You can implement JSON-RPC server and client.

Categories