What is a database abstraction layer? Why we are using it? What is the different between Database abstraction layer and Database specific coding?
Abstraction means ... providing interface .. so database abstraction is like u r providing interface for query like select , insert,update ... but implementation may be differ in coding layer . Please correct me if I am wrong
it's an interface which unifies the communication between a computer application and databases. in essense it enables and reduces the amount of work needed to "communicate" and interfaces with the DB. hope I'm clear enough
Sorry to bring up a week+ old thread, but in case they (the author) is still around I'll give a good explanation: Moving away from technobabble that means little (aka, above posts), database abstraction is where you have something (a series of classes usually, ignore that if you don't understand it) to allow you to write database queries for one type of database - eg: MySQL - but then it'll work with no changes (other than an altered configuration setting obviously) on another type of database, eg: PostreSQL or SQLite. Might be clearer if I explain it the other way round as well: database-specific coding is where if you write it for MySQL, but if you can't use MySQL at some point in the future (for instance a new webhost not having it installed) you have to rewrite all of the application where it uses the database to work with another engine. Not with database abstraction though - with that you just change a setting. Aw darn, I'm still sprouting technobabble... sorry Ok, in database specific coding, you might write this (it's not very good code atall but it's just an example): <?php mysql_connect('host', 'user', 'pass'); mysql_select_db('name'); mysql_query('INSERT INTO `table` VALUES(`x`, `y`, `z`'); ?> PHP: whereas in database abstraction (not a very good way to do it but good enough as example): <?php $database_engine = 'mysql'; function abstract_connect($host, $user, $pass) { global $database_engine; // not actually sure the below would work, treat as pseudocode switch($database_engine) { case 'mysql': return mysql_connect($host, $user, $pass); case 'postresql': return postres-connect-function-here($host, $user, $pass); } // AND THEN MORE FUNCTIONS FOR THE OTHER THINGS LIKE abstract_query INSTEAD OF mysql_query (etc) HERE abstract_connect('host', 'user', 'pass'); abstract_select_db('name'); abstract_query('INSERT INTO `table` VALUES(`x`, `y`, `z`'); ?> PHP: That code's junk, and you'd probably not ever do it like that, but it's a good example of what I mean.