Kiran Sone
Kiran Sone

Reputation: 75

what is active record class in codeigniter framework?

I am new to CodeIgniter framework. I am going through CI documentation. I want to know what is active record class and why the name 'active_record'? Thanks...

Upvotes: 1

Views: 1299

Answers (3)

Bira
Bira

Reputation: 5506

CodeIgniter uses a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action. CodeIgniter does not require that each database table be its own class file. It instead provides a more simplified interface.

Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.

e.g:

$query = $this->db->get('mytable');
// Produces: SELECT * FROM mytable

Upvotes: 0

Muslim
Muslim

Reputation: 66

For an explanation of an active record, read here. Examples of queries using Active Record and Without Active Record.

Query with active record :

$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

$query = $this->db->get();

Query without active record :

SELECT * FROM blogs JOIN comments ON comments.id = blogs.id

I hope this helps.

Upvotes: 1

Brian Ruchiadi
Brian Ruchiadi

Reputation: 361

It is a way to manipulate data from and to database such as Insert, Create, Display and Delete.

Upvotes: 0

Related Questions