Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

I have a SQL statement in my model,

I then say

$query = $this->db->query($sql, array(fields, fields1);

if ($query) {

    return true:

} else {

    echo "failed";

    return false;


My query always fails, how do I get PHP to print the exact SQL statement being sent to my database? And display that on my PHP view, page

1 Answer

0 votes
by (40.7k points)

Use the below query to display the query string:


To display the query result follow this:


The Profiler Class can display benchmark results, queries you have run, and $_POST data at the bottom of your pages. 

To enable the profiler place the below line anywhere within your Controller methods like this:


Profiling user guide:

You can learn in-depth about SQL statements, queries and become proficient in SQL queries by enrolling in our industry-recognized SQL online course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 29, 2020 in SQL by Appu (6.1k points)

Browse Categories