What is the best and most secure way to access a remote MySQL database?

I am about to develop a cloud application in java

, I have a Linux web server installed withmysql

so I come up with two different ways to query the database, both solutions exchange data http requests

and both methods have their own advantages and disadvantages.

I am using below example to demonstrate solutions

database on server

-- fruit--
name    price
Apple     10
Banana     5
Mango      4

      

will say that I want to get all fruits from the database

Solution 1 : write a database access class with PHP

server side help and let java app send request via http requst
ex: - java app will send request SELECT * FROM fruit

then server side PHP

will return request result in `JSON 'format

- it is super reusable and can be used for any future cloud database access and it is clean code because all implementations are not included aside java

except the database access

Solution 2 : write the classes of the Fruit class and the database server side and let the application java

call server side functions via http

requests
it asgetAllFruits()


- this way I have to implement all DAO classes on the server side and this is more coding, less reuse in another project, since DAO is implemented in PHP, maintenance support is higher than solution 1

I think solution 1 is the best because of the usability and simplicity, I am afraid that the database query will be sent via a http

query that does not feel good to me, so I really appreciate your ideas and comments as I am new to such applications if you have any other solutions or advantages and disadvantages I am also open to these

Also I was wondering how other companies are implementing it

+3


source to share





All Articles