Node.js and API to save to MySQL - php

I'm developing an API in PHP using the micro application feature from Phalcon Framework. This API consists in receiving GET, POST, PUT, DELETE requests then return results from the MySQL database (the API has access to the database).
I'm developing a phonegap + ionic framework mobile application too and I need to connect all mobile users in realtime. Something like a chat, with informations returning from the API, for example: All profile informations like name, email, age, birthday will be stored and retrieved using the api.
My question is, its all possible to implement node.js here to make the app real time? Is there another way (using only ajax)? Ill need to create interactions between users, example: Someone will make a friend request to another user in real time, if the requested user accept the solicitation, it uses the api to update the mysql database, adding the user to the friendlist.
I want to use API because I dont want to give the future developers, the database access.

Related

sending automatic push notification from mysql to android mobile

I have a database that contains some data and i want to get notified automatically on my mobile app if any value in the database is changed without having to check the database every certain time,i have tried many methods and viewed several tutorials but it leads me no where,any help ??
This is not going to be possible with only database. You need to write down an RESTful API which your app needs to poll to look for changes.
Ideal way of doing it is using GSM to push notify your app when ever you change something in your app. This will again require PHP/ASP/NodeJS etc... There must be some way you are updating your database? This should go exactly there.

PHP/CodeIgniter as middleware for mobile apps and website

I am planning to create a website and a web-service using Codeigniter (3.0.5). This web-service will serve data to the website.
But in the future I will create a mobile app using the existing web-service as data source.
This web-service will provide JSON response in every request from website/mobile apps.
My questions:
Since the website will access the web-service in curl/browser-less, session will not work. How I authenticate/keep-alive existing users which currently accessing the website/mobile apps?
Imagined answer: each time user authenticate, should the web-service creating some sort of session/user key with expiration time to the website and the key must be sent back from the website to the web-service for each request?
I want the web-service is only accessible from my website and mobile apps.
Imagined answer: create API/web-service key. The website/mobile apps must sent both the API key and session/user key I mentioned above. But from what I read, an API key are not supposed to stored in the mobile apps. How do I keep the api key secure?
Almost a year after this question is posted!
I was stopped looking at oauth because I dont really understand the implementation. But after re-search, apparently JWT (JSON Web Token) is the best solution for my situation.

Storing and displaying data in Cordova app

I'm creating this Cordova (Phonegap) app where I store users personal data (username and scores) every 60 seconds after which I want to display all users data to everybody (like scoreboard). For this I obviously need something to first gather all the data from users and then showing it to everybody.
I tried sending data with ajax to php for database storage. Then I tried sending data with ajax to php file to write the data in file, and finally realized that ajax won't work locally(?) (yes, I'm a novice). How do I create this kind of "global memory" that is accessible by all the users? How this is normally achieved in apps? I'm open for ideas.
Thanks.
You need a backend service, and call it from your application with webservices. You should send the data to your server (via webservice), store it in a database, and generate another call to send the scoreboard to every user.
Google about Rest APIS, choose the one you like.
For storing into the app, using localstorage is OK if the data is not too big. If it is, maybe you need to use SQLite, accesible from the cordova API.

linking android application to the mysql database phone and link the info as well

Hey guys im faced with a challenge of linking my localhost mysql/php when adding something in a form that form should also be linked with my android application.
ex. I have made a form for the admin whereby they could add a new bus route and it will be stored into their database using php mysql in localhost server now that new route should also be linked to my android application it should display the new route (My android application uses sqlite database so two different database here) so when users use the application when they search for new route it should also display as well
How can i go with that? any ideas please im really stuck in this
thank you
Well there are generally 2 approaches to follow when you want to 'Sync' your web database to your mobile database
Push Notifications: You could send a push notification to all your users, whenever a new route is added to the mysql db. When the notification is received by your app, (it's not necessary you show the notification to the user) you could just ping the server for the new route, or you can send the 'route' in the message part of the push notification if you can, and then add this new route to your sqlite database.
AccountManager: Using the AccountManager is the preferred method when you want to Sync your data. The AccountManager uses the SyncAdapter to Sync your apps data with it's cloud. When Android pings the servers of other apps for syncing, it pings your app's server too, and syncs your data. This method also takes care of issues like, if the internet connection was not working when it was intended to sync, so android will schedule the next sync soon.
To provide a good service, you should take a look at a client-agnostic API architecture.
In this architecture, you have a PHP/go/whatever-written API, that can or can not be REST (but it's reccomended), that will provide, given a HTTP petition, the desired result.
Using PHP in the simplest way, you should create different .php files, one for each action ( www.myserver.com/getRoutes.php, www.myserver.com/getRouteDetail?routeId=3), and make those PHP files query the MYSQL database and return (echo) XML / JSON / Raw text.
this should then be parsed by your mobile application, and added/updated to your SQLite database.

passing user information from php to django

I am building a web app in django and I want to integrate it with the php web app that my friend has build.
Php web app is like forum where students can ask question to the teachers. For this they have to log in.
And I am making a app in django that displays a list of colleges and every college has information about teachers like the workshop/classes timing of the teachers. In my django app colleges can make their account and provide information about workshop/classes of the teachers.
Now what I want is the student that are registered to php web app can book for the workshop/classes provided by colleges in django app and colleges can see which students and how many students have booked for the workshop/classes.
Here how can I get information of students from php web app to django so that colleges can see which students have booked for workshop. Students cannot book for workshop untill they are logged in to php web app.
Please give me any idea about this.. How can I make this possible
You must use one of these possibilities:
Your friend gives you direct access (even only read access) to his database and you represent everything as Django models or use raw SQL. The problem with that approach is that you have a very high-coupling between the two systems. If he changes his table or scheme structure for some reason you will also have to be notified and change stuff on your end. Which is a real headache.
Your friend provides an API end-point from his system that you can access. This protocol can be simple GET requests to retrieve information that return JSON or any other format that suites you both. That's the simplest and best approach for the long run.
You can "fetch" content directly from his site, that returns raw HTML for every request, and then you can scrape the response you receive. That's also a headache in case he changes his site structure, and you'll need to be aware of that.
If you cannot get the data from database directly then ask your friend to implement URL alike /students_info?book=bookname that returns in JSON format list of the students that ordered mentioned book.
In your python app
import urllib, json
url = "the url to php app/students_info?book=bookname"
response = urllib.urlopen(url);
data = json.loads(response.read())
You could try with REST, ie: Django rest framework and create a web API. By this way, you could send JSON data between Django and PHP.

Categories