What are Active Records ?
Active records are basically the design patterns, which are used for dealing with the databases. Codeigniter package contains a class of ACTIVE RECORDS. This pattern of active record allows its users to insert, select, delete and update etc from database with plus point of minimal scripting. You do not need to write long queries e.g here is query in core PHP
Select * FROM MyTable Where id = 1;
Now the same query in codeigniter with Active records is:
$this->db->where('id',1)
->get('Mytable');
Why use Active Records?
Active records has some of advantages, which are
- it allows minimal scripting, it shorten the queries
- Active records allows you to make database independent applications. Manual quries like mentioned above runs only on Mysql . But active records allows you to make database independent applications. Active records can be used in all the database that are supported by codeigniter
- Active records make your database more secure against sql injections.
- This can help support a clean separation of concerns and independent development that allows parallel, simultaneous development of application layers.
- Code reusability
- Application maintainability
Active record functions:
Well in this post I can not tell you all the functionality in the database class of the codeigniter, but I can tell you the basic ones. You can find all the details in the user guide or documentation of codeigniter which I talked in my first post. Some of the functionalities are:
$this->db->insert();
$this->db->delete();
$this->db->update();
$this->db->select();
$this->db->where();
$this->db->get();
$this->db->limit();
For more functions, visit the documentation of codeigniter. here is the link https://www.codeigniter.com/user_guide/
I hope this post was a help for you, leave your queries in the comments below, God bless you all !
I use datatables for select, for update, insert, delete I use stored procedures. Now, I can get data to datatable from stored procedure too.
ReplyDeleteYes sir ! You can get it fir sure ! Any other thing you want help with ?
Delete