Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting CodeIgniter Active Record's current SQL code

for example, i want to convert this;

$this->db->get('table'); 

to this;

'SELECT * FROM table' 

is there any function for this? i searched on the user guide of CI but didnt find any solution.

like image 579
WhoSayIn Avatar asked Sep 03 '10 18:09

WhoSayIn


People also ask

Where is active record in CodeIgniter?

Active Record ClassCodeIgniter 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.

How do you check data is updated or not in CodeIgniter?

Mirov When we are working with codeigniter, the data only updated when there is some change in the input field's value and then the $this->db->affected_rows() will return value greater then 0.

How do I print a query in CI?

Use the below query to display the query string: print_r($this->db->last_query()); To display the query result follow this: print_r($query);

What is CodeIgniter active record class?

Active Record Class 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.

What is the CodeIgniter 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.

What is CodeIgniter query builder?

Query Builder Class CodeIgniter gives you access to a Query Builder class. 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.

Should I use CodeIgniter active record or write raw query?

If you are thinking for performance, best is to avoid active record and write raw query. But, if you are not comfortable in writing raw query and looking for a codeigniter active record based alternative solution, there is one for you as well.


1 Answers

You can also use $this->db->get_compiled_select(). The difference between get_compiled_select() and last_query() is that get_compiled_select() gives the query string generated even if you don't run the query against the database.

like image 127
Sandy Avatar answered Sep 17 '22 16:09

Sandy