What is the purpose of Active Records?
activerecord, codeigniter, database, php
Solution
The "Active Record Pattern" is becoming a core part of most programming frameworks. It makes simpler CRUD (Create, Update, Read, Delete) tasks quicker to achieve. For example rather than having to write many SQLs to Insert, Update and Delete many common and simple data objects, it allows you to simply assign the values to the data object and run a command e.g. $object->save(), the SQL is compiled and executed for you.
Most frameworks also implement data relationships within their respective Active Record models which can greatly simplify accessing data related to your object. For example, in CodeIgniter, if you specified that a Category "has many" Products then after loading the Category object from the database, you can list it's child Products with a simple line of code.
foreach ($category->products as $product) {
echo $product->name;
}
Another benefit of Active Record is, as you say, that it makes your code easily portable to different database platforms (so long as the framework that you are using has a driver for your chosen database) and although this is not likely to seem important right now, it my have greater value at a later date if your application becomes popular!
Hopefully this will have helped. Wikipedia describes Active Record well (http://en.wikipedia.org/wiki/Active_record_pattern) and the CodeIgniter docs will aswell. Personally, I use KohanaPHP (http://www.kohanaphp.com) which is a PHP5 only fork of CodeIgniter and I find that it's ORM models are very useful!
Problem
I'm tinkering with CodeIgniter and have come across Active Records for the first time. At first I dismissed it as something for people who don't really know how to write SQL. I realise now that my analysis was flawed and Active Records are pretty prominent, especially in Rails. But what purpose do Active Records hold? Is it to abstract away from different RDBMS individualities. If so I thought that isn't that what SQL is meant to do. Furthermore what is best practice, should I be using these? Thanks in advance