I need a very simple explanation because I'm not a professional programmer.

I found the terminology "abstraction layer" reading the documentation of mysqli extension where is described the difference among mysql, mysqli and PDO extensions in PHP. The article is this, that's where I met "abstraction layer" for the first time (referred to PDO).

Now, trying to elaborate my question, we could speak of PDO abstraction layer against mysqli extension in php. So, for example, why mysqli is not defined as abstraction layer? How an abstraction layer acts? (like PDO in php)

I would like to understand in a general way what is an"abstraction layer", I will not do particular questions about php or mysqli and PDO extensions.

So, what is an abstraction layer? And what is its difference from a common application's extension?

  • 4
    It's a layer that abstracts underlying functionality. Can you elaborate on what exactly is causing your confusion? Perhaps by quoting some articles? Commented Jan 12, 2014 at 17:31
  • 2
    @JeroenVannevel the only article I can post is this, that's where I met "abstraction layer" for the first time (referred to PDO). Now, trying to elaborate my question, we could speak of PDO abstraction layer against mysqli extension in php. So, for example, why mysqli is not defined as abstraction layer? How an abstraction layer acts? (like PDO in php)
    – marco
    Commented Jan 12, 2014 at 18:02
  • 1
    @JeroenVannevel If you should represent an abstraction layer with an image (or a metaphor) what would be your image? You know, sometimes we can use images to figure a concept (for example, in a program language we see a variable like a box, an array like a set of box, and so on), sometimes it helps...
    – marco
    Commented Jan 12, 2014 at 18:09
  • I watched some introductory level videos on YouTube last night and one addressed this. It's here youtube.com/watch?v=p7nGcY73epw. Check out their other stuff, nice explanations.
    – user1248
    Commented Jan 12, 2014 at 18:13

4 Answers 4


Often an abstraction layer is commonly used to 'abstract' away detail.

Say you had a program for moving money around between different banks. There is a function for moving money to BankA, and a different function for moving money to BankB and so on. The different functions might exist because the information that different banks request varies (As a simple example maybe one requests the senders first name and surname, and another requests the senders first initial and surname).

Your functions might be:

MoveMoneyToBankA(amount, accountNo, senderFirstName, senderSurname)
   ... Code to move money to bank A

MoveMoneyToBankB(amount, accountNo, senderFirstInitial, senderSurname)
   ... Code to move money to bank A

To abstract away all the different things a program needs to think about when communicating with different banks, an abstration layer might be implemented by adding the function 'MoveMoneyToBank'

MoveMoneyToBank(amount, accountNo, senderFirstName, senderSurname, bankName)
   ... If bank name = 'BankA' call MoveMoneyToBankA

   ... If bank name = 'BankB', find senderFirstInitial using senderFirstName, and call 'MoveMoneyToBankB'

So what you have done here is abstracted away the detail that needs to be managed when communicating with two different banks. A programmer can now just use the general MoveMoneyToBank function, and not have to think about the different requirements of each bank.

In reality, this might not just be functions with in the same program, but even different projects within the same solution, or a new software project that draws in lots of components and deals with the complexity of working with all the separate components to achieve a common goal.


Generally, an abstraction layer is an API (set of functions) which is hiding the underlying implementation/complexity. The purpose is to provide a clear and easier-to-use interface over an existing set of functionality.

Imagine you want to create a stack using a list. You could build a class called Stack. You'd have a private list inside it to store the elements. You'd also have methods to push and pop elements from the stack. This class is an abstraction layer over list representing a stack. It hides the implementation (how elements are stored, how they are pushed and popped) and provides a simple interface to work with a stack.

The wikipedia article about abstraction layers is a good starting point.

Regarding database abstration layers. For example, you have a MySQL database and you want to access it from your PHP program. An abstraction layer in this case would provide the funtionality of opening connetion to the database, executing queries, calling stored procedures, etc. So when working with the database from PHP code, you won't have to think about how connection is actually created or how MySQL queries are actually passed to the database, executed there and how the result is returned and parsed.


I think that under most circumstances, an abstraction layer serves as a simplification or gateway to a more complicated underlying layer.

Suppose you have a database layer that allows you to perform nearly all database operations you can imagine. However, such a layer or API would be fairly complicated to use due to its number of features. Especially if you just want to do something simple.

In this case, an abstraction layer might be available that only provides a subset of the functionalities in an easier to use fashion. While still using the underlying layer, this layer could then provide more intuitively named methods/functions, easier to use parameters and/or predefined parameters that should help you get started...

Often times, such abstraction layers also introduce more general or real world concepts that are more easily understood by people that are no domain experts. (To give a technical example: the database layer could return you a resultset that needs to be iterated, while the abstraction could return you a list of well defined objects that are ready to be used)

While such underlying layers provide greater functionality, they usually require more time to get something done if you are not yet familiar with it.


Why (do we need them)

We make an "abstraction layer" to focus on the task at hand. It's also helpful for managing systems, and for mental comfort.

What (are they)

An "abstraction layer" is a piece of technology - function/class/software/device, that does some work for you without you having to specify or worry about the details of "how" it works.

Examples (general):

  1. Car engine is an abstraction for a driver, who only needs to know about the controls - steering wheel, pedals. They don't have to worry about how the engine works.
  2. Food delivery app - the user only needs to know how to select items and pay. They don't need to worry about preparation, delivery, etc.

Software examples:

  1. Internet APIs - you just have to call the YouTube API to get video details, and don't need to worry about how to get data from the database, package it and send it.
  2. Operating system (Windows, macOS, Linux...) - you just have to give commands in the terminal, and the OS manages everything else.
  3. Public functions (in OOP) - expose a consistent set of "public" functions and variables, which in turn use "private" functions/variables. Holds for other programming paradigms too.
  4. fetch/XMLHttpRequest - you can use a fetch/XMLHttpRequest call in a browser, without having to worry about how this call is converted into electromagnetic waves by your laptop's network card, sent to your Wifi router, etc.

Obviously, someone else (or you yourself) has to make the abstraction layer, which might be built on the "top" of yet another (deeper) abstraction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.