What is Database Abstraction Layer?
Database Abstraction Layer, like what its descriptive name suggests, is an API layer that contains abstracted data from the methodologies and procedures of vendor-specific databases, and creates objects that Developers can re-use to obtain data from databases. Put simply, you are able to use 1 dialect to communicate with many different databases, regardless of what specific dialect a database may have.
Examples (PHP)
Database Abstraction Layer, like what its descriptive name suggests, is an API layer that contains abstracted data from the methodologies and procedures of vendor-specific databases, and creates objects that Developers can re-use to obtain data from databases. Put simply, you are able to use 1 dialect to communicate with many different databases, regardless of what specific dialect a database may have.
Examples (PHP)
DATABASE | ACTION | METHOD |
MS SQL Server | Fetch a result row as an associative array, a numeric array, or both | mssql_fetch_array |
MySQL | Fetch a result row as an associative array, a numeric array, or both | mysql_fetch_array |
SQLite | Fetches the next row from a result set as an array | sqlite_fetch_array |
Sybase | Fetch a result row as an associative array | sybase_fetch_assoc |
PostgreSQL | Fetch a row as an associative array | pg_fetch_assoc |
The examples shown above describes how different databases uses their own "dialect" or methods to perform actions that are somehow similar with one another. And just like human languages, some of methods by a specific database may not have direct equivalency with other databases' methods, and may require more methods in order to perform similar action.
By using Database Abstraction Layer, the Developers will only need to learn 1 API to implement the same actions; and this layer will communicate with the databases to perform the actions you want.
Possible Advantages
Possible Disadvantages
Personally, I support Database Abstraction Layers because it promotes good practice and code consistency. The possible disadvantages can only occur under certain conditions in some cases such as:
1) A Developer chose a route that requires database operations not supported by specific databases, which may not be necessary because in reality, most of what you need are supported. And there are many solutions that can accomplish the same task.
2) An application, regardless of size, that uses more than 5 types of databases, which will somehow force the specific databases that do not have the tools to perform tasks commanded by the layer API, to try to understand and attempt to process the requests, which results in slower performance and longer processing. In this case, then using vendor-specific databases' languages would be more suitable.
It's always a case-to-case basis. For me, Database Abstraction Layers are still Developers' great friends.
By using Database Abstraction Layer, the Developers will only need to learn 1 API to implement the same actions; and this layer will communicate with the databases to perform the actions you want.
Possible Advantages
- cleaner code
- structure
- consistency
- faster development cycle
- ease of use
Possible Disadvantages
- additional dependency
- overheads
- slower speed
- limit on database operations
Personally, I support Database Abstraction Layers because it promotes good practice and code consistency. The possible disadvantages can only occur under certain conditions in some cases such as:
1) A Developer chose a route that requires database operations not supported by specific databases, which may not be necessary because in reality, most of what you need are supported. And there are many solutions that can accomplish the same task.
2) An application, regardless of size, that uses more than 5 types of databases, which will somehow force the specific databases that do not have the tools to perform tasks commanded by the layer API, to try to understand and attempt to process the requests, which results in slower performance and longer processing. In this case, then using vendor-specific databases' languages would be more suitable.
It's always a case-to-case basis. For me, Database Abstraction Layers are still Developers' great friends.