Question: Is there any difference between using
Answer: No. Both do the same sort of job.
Explanation
If You need to get know about CI Transaction Read this answer on another question.
But By only using $this->db->query()
you can't archive transaction part comletly.
I Recommend this personally Read this Documentaion
Question: When do you explicitly write out that you want to begin a transaction in a query and when do you just invoke a built-in method from the framework or whatever language you are using?
Answer: (based on PHP/CI)It's based on what kind a system you do.
Explanation
For example, if you have simple product add and its have many child tables. (assume 1 master and 4 child tables). so once one of the child table throws an error, data remain at the upper-level table. So to prevent that we should use Transaction on here.
Assume Child Table 2
occurred an error and this what happens (for Inserted Data).
| Table Name | Normal Insert if |
/update | Transaction |
| ------ | ------ | ------ |
| Master Table | Remain | Roalbacked |
| Child Table 1 | Remain | Roalbacked |
| Child Table 2 | Error | Roalbacked |
| Child Table 3 | Empty | Nothing to do |
| Child Table 4 | Empty | Nothing to do |
Useful Links
- Transactions - codeigniter.com
- My Answer on another question
- php-mysql transaction - mysqltutorial.org