Accessing MySQL Database

Posted on

Question :

I am designing a database for an application, which will be accessed by different front end programming languages, such as php,, android applications and iphone applications.

I am confused, whether is it good to accessing different programming languages directly to a database? and I learned somewhere, I have to create a middle layer between database (Backend) and Programming languages (Frontend).

  1. Is this middle layer indicating Stored Procedure?
  2. If it is not stored procedure what is required to create this middle layer?
  3. If my overall logic is wrong kindly suggest me any other method to solve this doubt.
  4. Is there anything related to middle layer which I need to concentrate while designing?

Thanks in advance.

Answer :

If you were only talking about accessing the database via PHP and, then a stored procedure could serve as a common middle layer. Once you add the android and iphone applications into the equation, you’re looking at having to design another middle layer. Reason for that it is most mobile devices don’t have database drivers available to them.

In your case, you should build your middle layer in or PHP as a web service. Most are designing these web services as a REST API. You’ll need to think about the information that your mobile apps need and build API endpoints for those things (users, posts, etc). I also recommend making your and PHP site/application use the same API your mobile apps do.

By setting up an API like this, you can reduce the work required for your apps. You’re mobile app doesn’t know that to get the latest 10 posts, it has to query SELECT * FROM posts order by create_date desc limit 10. It just has to make a request to http://myapi/posts/latest.

There are several posts on Stack Overflow and Programmers.SE about setting up Web Service APIs, I recommend reviewing them.

Leave a Reply

Your email address will not be published. Required fields are marked *