Is it OK to access one database from two different application endpoints? - php

I already have a web app that uses raw PHP to access a database. Now I want to create a mobile app using react-native, that will be a mobile version of the web app, thus use the same database. What is the best way to implement the mobile app?

You can create a Rest API both for your web app and mobile app. So they can share same logic as backend.

Related

Connect React Native app to a laravel web app with MySQL Database

I'm currently building a new project that needs a web app and mobile app and i'm forced to work with Laravel and React Native.
So my question is if I can connect between the two app's using MySQL ?
PS: I already searched and i did find this topic here, but i didn't get the idea clear.
Laravel can be just a backend and React-Native is a front-end. Your React-Native can talk to a Laravel backend without any problem or can share a database such as MySQL, it is no different then using a Node, ASP.NET, Ruby or even a Perl backend for your React-Native app to serve a REST API and connect to a database.
Not knowing the details of your website, I would look to build a REST API that can be used by React, React-Native (iOS android, or both) and the laravel based website. Certain features like authentication should easily work cross platform, other API calls may need to be tailored to Mobile vs Web. The backend can be Laravel or any other system include Node as long as it is a REST API, both the site and app will be able to use it.

Best approach in using a MySQL database for crud functionalities in both web and mobile app

I've developed a website with the usual crud functionalities in Codeigniter and MySQL. I'm now tasked with creating a mobile app (with the same functionalities ) in Ionic 2.
To access my database with Ionic, I created a REST api -- which I was able to manipulate smoothly.
My questions are:
How, or can I, use my MySQL users' credentials to log in on my Ionic 2 app?
How can my web and mobile can share the same database?
I've been reading a lot about Fire base,etc. However, my tiny brain is unable to comprehend whatever I read. If anyone can point me to right direction, I would highly appreciate it. Thanks!
When developing an Ionic App you have to think of it as if you were developing a regular website. The only difference is that you have access to native device features with cordova plugins, but the whole flow is almost exactly like in a regular website (it is an angular application after all).
This means you can use your API just like you use it in your website. There is no need to use firebase. (Firebase is kind of like a database itself that you could use INSTEAD of your MySQL backend)
Totally agree with #Andreas. When you build a modern application that supports on the different platforms such as web or mobile, you need to design a standard API and then next step is to build a web application/mobile app to consume this API. And because of all the web/devices are all consuming from the same API, they are interacted with the same database. Unless they are using different API.
Can refer to the image below for easy understanding.
So talk about how authentication and authorization can be done from the mobile app or from the web app. You should take a look at OAuth2. It is a protocol for securing API services from untrusted devices, and it provides a nice way to authenticate mobile users via what is called token authentication.
The workflow will look like below, on both web and mobile app.
A user opens up your mobile app and is prompted for their username or email and password.
You send a POST request from your mobile app to your API service with the user’s username or email and password data included (OVER SSL for sure. If you don't know about it, google it).
You validate the user credentials, and create an access token for the user that expires after a certain amount of time.
You store this access token on the mobile device, treating it like an API key which lets you access your API service.
Once the access token expires and no longer works, you re-prompt the user for their username or email and password.
Reference
REST API from PHP
The ultimate guide for Mobile Security

Sync Mobile App and Web App without third party services

Currently building a hybrid app. using Ionic Framework with PHP for backend services
I am having a case where a user has got his profile in Web app and Mobile App as well.
If the user adds two stories as favourites (Its kind of a reading app) from his mobile app or Web app,how do I sync that?
Here are the scenarios:
1) User marks the stories favourites from web app and when I come online through mobile app, display it.
2) User marks the stories favourites from mobile app when he is offline(Now this will be stored in LocalDB). So again when he comes online sync with the server?
I know there are services like Firebase which provides syncing service.
But What If I would want to develop a Custom Syncing service on my own for my application? Is that an extremely complicated process?
If yes and it can be developed ,then how should I proceed ? A basic idea? What are the best practices that I should consider?
Any links would be appreciated?
I know some of the comments recommended CouchDB in combination with PouchDB. That is a much better solution than trying to implement your own synchronization service with MySQL.
However, since you're using Ionic Framework you can also use Couchbase. Take the following example application:
https://github.com/couchbaselabs/TodoLite-Ionic
If you chose this solution you would have three moving parts. You would be replacing MySQL with Couchbase Server and running the Couchbase Sync Gateway to orchestrate any data between the device and the server. You can still keep your PHP backend if you have a web version of your application as there is a PHP SDK for Couchbase.
Two write-ups on this can be found here:
http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-1
http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-2
In the long term, you're going to find NoSQL much more pleasant to work with when it comes to APIs and mobile than MySQL.
Can be useful to write a POST method on the backend that receives the data from your local from the app and some user data (session, access tokens and other thing you considered neceasary). On the body for the request you include the data needed to be synced. The backend takes the body. Parse it and rreturn a result (http code) Based on that you can decide if the app should delete the local data or only mark it as synced on the local database

iOS Application, Website, and Web Service - Should I use a framework?

I am developing an iOS application that will be communicating with a PHP/MySQL web service to send/receive data. My plan is to also have a website that has similar functionality to the iOS application and will also interact with the web service. Should I be using a framework to build this web service (I am thinking about Laravel)? Is it a good idea to have the web service separate from the website?
Thanks.
If you are building a native application and requires connection to your website or collecting info, I suggest you to build you own API to access the data from ios using json.

Will iphone app retrieve the pages from the server or from the app itself?

I'm new to iPhone app development. I'm building app using phonegap by importing my all html css and javascript.
My doubt is if I'm using php at the backend can i make request similar to web from the iphone app. Will iPhone app retrieve the pages that is processed from the server?
PhoneGap can access web sites listed in the WhiteList and obtain responses from them, e.g. web pages.
But such an application possibly will not pass AppStore approvement, because of it can get malicious dynamic content. (This is just my personal assumption.)

Categories