Codeigniter why use active record
Here is how: Lets assume we are merging two different column into one in a same database table One of the possible reasons for which we need to use UNION. Code should be something like this:. Here, what we are doing is simply getting help from codeigniter active record class to prepare two different query and then we are manually constructing our original query. Github: ranacseruet.
The problem is — it runs 3 queries — which 2 of has no use, except to compile sql statement. You might as well write the query as a string. Why run 2 additional queries to get the string output? Hi, Thanks for your feedback. Yes, I do know also that its not a quite good practice. I better hope that, codeigniter active record class do get a new release with this features in near future.
Additionally, as you suggested I will mention it in the original post. Thank you for sharing this information. Generates an update string based on the data you supply, and runs the query. The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key. The first parameter is the table name, the second is the where clause.
An array of table names can be passed into delete if you would like to delete data from more than 1 table. Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:. Normally, when an Query Builder call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.
Cached calls are cumulative. If you make 2 cached select calls, and then 2 uncached select calls, this will result in 4 select calls. There are three Caching functions available:. This function must be called to begin caching. All Query Builder queries of the correct type see below for supported queries are stored for later use. That in turn will i. Resets the current Query Builder state. Inserting data Inserting data using Active Record is a very simple process, and there are just two functions that you may need to use in order to insert data into your database.
This will generate an insert string based upon the data that you supply to it. The first parameter is the name of the table that you want to add the data to, and the second parameter can either be an array or an object of the data. The first parameter is the name of the table you want to add the data to, and the second parameter can either be an array or an object of the data. You can optionally use the where method to set the where clause of the query.
The first is the name of the table, and the second should be an array from which to build the WHERE clause. An array of table names can be passed into this function, if you wish to delete more than one table. My keen interest in technology and sharing knowledge with others became the main reason for starting PHPGurukul. August 2, December 17, In the above code, WHERE clause helps in extracting only the records that satisfy the given condition.
For Example,. When multiple function calls are occurs, the result will be grouped together with AND between them. Table names can be passed as an array into the function delete when required to delete data from multiple tables. CodeIgniter Active Records Chapter CodeIgniter - Application
0コメント