Tags
Asked 2 years ago
17 Jun 2021
Views 238
Etha

Etha posted

Getting raw SQL Queries in CodeIgniter 1.7

Getting raw SQL Queries in CodeIgniter 1.7
sandip

sandip
answered Apr 27 '23 00:00

2 / 2

To get the raw SQL query of a CodeIgniter 1.7 query, you can use the $this->db->last_query() method.

Here's an example of how to get the raw SQL query of a CodeIgniter 1.7 query:



$this->db->select('column1, column2');
$this->db->from('my_table');
$this->db->where('column1', $value1);
$this->db->where('column2 >', $value2);
$query = $this->db->get();

$sql = $this->db->last_query();
echo $sql;

In this example, we are selecting columns named "column1" and "column2" from a table named " my_table". We are then applying two where conditions to the query using $this->db->where(), and retrieving the results using $query = $this->db->get().

Finally, we are getting the raw SQL query of the query using $this->db->last_query() and echoing it using echo $sql;.

You can modify the example to suit your specific query needs, changing the table name, column names, and where conditions as necessary. Note that you should properly sanitize any user input to prevent SQL injection vulnerabilities.
Post Answer